foxclaw 0.1.0 → 0.1.2
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.
- package/README.md +54 -29
- package/bin/foxclaw.cjs +51 -0
- package/index.js +11 -10
- package/package.json +46 -38
- package/python/.dockerignore +35 -0
- package/python/.env.example +165 -0
- package/python/.gitattributes +46 -0
- package/python/.github/workflows/ci.yml +122 -0
- package/python/.github/workflows/release.yml +183 -0
- package/python/Dockerfile +64 -0
- package/python/LICENSE +21 -0
- package/python/MANIFEST.in +14 -0
- package/python/README.md +192 -0
- package/python/README_CN.md +324 -0
- package/python/bench/bm25_audit.py +199 -0
- package/python/bench/bm25_regression.py +178 -0
- package/python/bench/bm25_stress.py +159 -0
- package/python/bench/cd_audit.py +238 -0
- package/python/bench/chaos.py +142 -0
- package/python/bench/concurrency.py +103 -0
- package/python/bench/e2e_real_models.py +95 -0
- package/python/bench/llm_retry_test.py +248 -0
- package/python/bench/load_test.py +196 -0
- package/python/bench/vector_ivf_upgrade.py +134 -0
- package/python/docs/CHANNELS.md +195 -0
- package/python/docs/GOVERNANCE.md +164 -0
- package/python/docs/RELEASE.md +109 -0
- package/python/docs/RUN.md +75 -0
- package/python/docs/RUN_CN.md +121 -0
- package/python/docs//351/205/215/347/275/256/346/214/207/345/215/227.md +152 -0
- package/python/evals/__init__.py +0 -0
- package/python/evals/governance/README.md +61 -0
- package/python/evals/governance/__init__.py +0 -0
- package/python/evals/governance/cases.py +152 -0
- package/python/evals/governance/compare_embeddings.py +94 -0
- package/python/evals/governance/convergence.svg +11 -0
- package/python/evals/governance/report.json +371 -0
- package/python/evals/governance/run_evals.py +400 -0
- package/python/examples/governance_middleware_demo.py +77 -0
- package/python/examples/langgraph_governance_demo.py +108 -0
- package/python/examples/sample_itinerary.csv +6 -0
- package/python/examples/sample_knowledge.csv +9 -0
- package/python/examples/sample_transactions.csv +14 -0
- package/python/foxclaw/__init__.py +526 -0
- package/python/foxclaw/agents/__init__.py +12 -0
- package/python/foxclaw/agents/agents.py +35 -0
- package/python/foxclaw/agents/base.py +865 -0
- package/python/foxclaw/agents/impl/__init__.py +1 -0
- package/python/foxclaw/agents/impl/_helpers.py +78 -0
- package/python/foxclaw/agents/impl/finance.py +248 -0
- package/python/foxclaw/agents/impl/office.py +367 -0
- package/python/foxclaw/agents/impl/supervisor.py +659 -0
- package/python/foxclaw/agents/mixins/_context.py +151 -0
- package/python/foxclaw/agents/mixins/augment.py +149 -0
- package/python/foxclaw/agents/mixins/llm.py +66 -0
- package/python/foxclaw/agents/mixins/memory.py +35 -0
- package/python/foxclaw/agents/mixins/preference.py +81 -0
- package/python/foxclaw/agents/mixins/prompt.py +77 -0
- package/python/foxclaw/agents/mixins/skillbox.py +58 -0
- package/python/foxclaw/agents/mixins/tool_exec.py +443 -0
- package/python/foxclaw/api/__init__.py +283 -0
- package/python/foxclaw/api/app.py +123 -0
- package/python/foxclaw/api/middleware.py +317 -0
- package/python/foxclaw/api/routes/ahs.py +417 -0
- package/python/foxclaw/api/routes/attachments.py +117 -0
- package/python/foxclaw/api/routes/browser.py +39 -0
- package/python/foxclaw/api/routes/domain.py +314 -0
- package/python/foxclaw/api/routes/knowledge.py +163 -0
- package/python/foxclaw/api/routes/llm_admin.py +461 -0
- package/python/foxclaw/api/routes/memory.py +89 -0
- package/python/foxclaw/api/routes/orchestration.py +41 -0
- package/python/foxclaw/api/routes/recovery.py +43 -0
- package/python/foxclaw/api/routes/review.py +275 -0
- package/python/foxclaw/api/routes/search.py +37 -0
- package/python/foxclaw/api/routes/system.py +327 -0
- package/python/foxclaw/api/routes/task.py +281 -0
- package/python/foxclaw/api/routes/ws.py +68 -0
- package/python/foxclaw/api/spine.py +55 -0
- package/python/foxclaw/browser/__init__.py +13 -0
- package/python/foxclaw/browser/action/__init__.py +1 -0
- package/python/foxclaw/browser/action/action_executor.py +54 -0
- package/python/foxclaw/browser/action/action_types.py +45 -0
- package/python/foxclaw/browser/action/action_verifier.py +68 -0
- package/python/foxclaw/browser/action/url_policy.py +147 -0
- package/python/foxclaw/browser/adapter/__init__.py +1 -0
- package/python/foxclaw/browser/adapter/base_adapter.py +23 -0
- package/python/foxclaw/browser/adapter/web_adapter.py +46 -0
- package/python/foxclaw/browser/driver/__init__.py +1 -0
- package/python/foxclaw/browser/driver/base_driver.py +61 -0
- package/python/foxclaw/browser/driver/playwright_driver.py +166 -0
- package/python/foxclaw/browser/perception/__init__.py +1 -0
- package/python/foxclaw/browser/perception/dom_extractor.py +43 -0
- package/python/foxclaw/browser/perception/element_indexer.py +57 -0
- package/python/foxclaw/browser/perception/semantic_reducer.py +33 -0
- package/python/foxclaw/browser/perception/snapshot.py +29 -0
- package/python/foxclaw/browser/service.py +148 -0
- package/python/foxclaw/browser/session/__init__.py +1 -0
- package/python/foxclaw/browser/session/session_manager.py +57 -0
- package/python/foxclaw/capability/__init__.py +12 -0
- package/python/foxclaw/capability/embedding_service.py +67 -0
- package/python/foxclaw/channels/__init__.py +140 -0
- package/python/foxclaw/channels/discord.py +184 -0
- package/python/foxclaw/channels/dispatcher.py +204 -0
- package/python/foxclaw/channels/feishu.py +225 -0
- package/python/foxclaw/channels/openclaw_bridge.py +156 -0
- package/python/foxclaw/channels/signing.py +187 -0
- package/python/foxclaw/channels/telegram.py +121 -0
- package/python/foxclaw/channels/weixin.py +225 -0
- package/python/foxclaw/cli.py +154 -0
- package/python/foxclaw/cognitive/__init__.py +4 -0
- package/python/foxclaw/cognitive/reasoner.py +82 -0
- package/python/foxclaw/cognitive/state.py +147 -0
- package/python/foxclaw/core/__init__.py +9 -0
- package/python/foxclaw/core/audit_chain.py +133 -0
- package/python/foxclaw/core/audit_sink.py +100 -0
- package/python/foxclaw/core/compaction.py +283 -0
- package/python/foxclaw/core/config.py +65 -0
- package/python/foxclaw/core/confirm_nonce.py +157 -0
- package/python/foxclaw/core/dispatch.py +27 -0
- package/python/foxclaw/core/envfile.py +48 -0
- package/python/foxclaw/core/failure_policy.py +151 -0
- package/python/foxclaw/core/gateway.py +85 -0
- package/python/foxclaw/core/governance_audit.py +175 -0
- package/python/foxclaw/core/idempotency.py +289 -0
- package/python/foxclaw/core/injection_guard.py +221 -0
- package/python/foxclaw/core/memory_adapter.py +516 -0
- package/python/foxclaw/core/metrics.py +89 -0
- package/python/foxclaw/core/model_router.py +1097 -0
- package/python/foxclaw/core/paths.py +103 -0
- package/python/foxclaw/core/recovery.py +362 -0
- package/python/foxclaw/core/scheduler.py +144 -0
- package/python/foxclaw/core/secrets.py +134 -0
- package/python/foxclaw/core/sessions.py +157 -0
- package/python/foxclaw/core/settings.py +430 -0
- package/python/foxclaw/core/shared_write.py +198 -0
- package/python/foxclaw/core/steering_queue.py +153 -0
- package/python/foxclaw/core/system_bus.py +84 -0
- package/python/foxclaw/core/thought_chain.py +318 -0
- package/python/foxclaw/core/token_meter.py +235 -0
- package/python/foxclaw/core/tools.py +172 -0
- package/python/foxclaw/core/tracing.py +390 -0
- package/python/foxclaw/core/truth_pipeline.py +114 -0
- package/python/foxclaw/core/vec_recall_adapter.py +503 -0
- package/python/foxclaw/core/verify.py +181 -0
- package/python/foxclaw/core/web_search.py +242 -0
- package/python/foxclaw/finance/__init__.py +15 -0
- package/python/foxclaw/finance/evidence.py +153 -0
- package/python/foxclaw/finance/fx.py +100 -0
- package/python/foxclaw/finance/graph.py +188 -0
- package/python/foxclaw/finance/models.py +150 -0
- package/python/foxclaw/finance/nlparse.py +575 -0
- package/python/foxclaw/finance/policy.py +329 -0
- package/python/foxclaw/finance/reasoner.py +129 -0
- package/python/foxclaw/finance/reasoning.py +340 -0
- package/python/foxclaw/finance/reconcile.py +180 -0
- package/python/foxclaw/finance/runtime.py +527 -0
- package/python/foxclaw/governance/__init__.py +24 -0
- package/python/foxclaw/governance/middleware.py +184 -0
- package/python/foxclaw/harness/__init__.py +17 -0
- package/python/foxclaw/harness/_base.py +72 -0
- package/python/foxclaw/harness/_policy.py +359 -0
- package/python/foxclaw/harness/drift.py +89 -0
- package/python/foxclaw/harness/event_bus.py +31 -0
- package/python/foxclaw/harness/harness.py +446 -0
- package/python/foxclaw/harness/loop_detection.py +152 -0
- package/python/foxclaw/itinerary/__init__.py +10 -0
- package/python/foxclaw/itinerary/amap_client.py +117 -0
- package/python/foxclaw/itinerary/models.py +80 -0
- package/python/foxclaw/itinerary/reasoner.py +101 -0
- package/python/foxclaw/itinerary/reasoning.py +174 -0
- package/python/foxclaw/itinerary/runtime.py +148 -0
- package/python/foxclaw/kernel/__init__.py +13 -0
- package/python/foxclaw/kernel/capabilities.py +73 -0
- package/python/foxclaw/kernel/policy_gate.py +114 -0
- package/python/foxclaw/kernel/process_manager.py +205 -0
- package/python/foxclaw/kernel/scheduler.py +131 -0
- package/python/foxclaw/kernel/sentinel.py +453 -0
- package/python/foxclaw/kernel/sentinel_client.py +246 -0
- package/python/foxclaw/kernel/spine.py +97 -0
- package/python/foxclaw/knowledge/__init__.py +376 -0
- package/python/foxclaw/knowledge/truth_crystallizer.py +92 -0
- package/python/foxclaw/learning/__init__.py +12 -0
- package/python/foxclaw/learning/knowledge_graph.py +149 -0
- package/python/foxclaw/learning/models.py +93 -0
- package/python/foxclaw/learning/reasoner.py +70 -0
- package/python/foxclaw/learning/runtime.py +363 -0
- package/python/foxclaw/learning/spaced_repetition.py +96 -0
- package/python/foxclaw/mcp_server.py +189 -0
- package/python/foxclaw/orchestration/__init__.py +184 -0
- package/python/foxclaw/pipeline/__init__.py +23 -0
- package/python/foxclaw/pipeline/cognitive_pipeline.py +481 -0
- package/python/foxclaw/pipeline/supervisor_stages.py +230 -0
- package/python/foxclaw/planning/__init__.py +17 -0
- package/python/foxclaw/planning/llm_planner.py +232 -0
- package/python/foxclaw/planning/planner.py +99 -0
- package/python/foxclaw/search/__init__.py +24 -0
- package/python/foxclaw/search/agent_port.py +194 -0
- package/python/foxclaw/search/evidence.py +113 -0
- package/python/foxclaw/search/external_search.py +50 -0
- package/python/foxclaw/search/hkc_read_port.py +60 -0
- package/python/foxclaw/search/internal_search.py +73 -0
- package/python/foxclaw/search/models.py +129 -0
- package/python/foxclaw/search/planner.py +44 -0
- package/python/foxclaw/search/retriever.py +39 -0
- package/python/foxclaw/search/runtime.py +134 -0
- package/python/foxclaw/search/strategy.py +44 -0
- package/python/foxclaw/skills/__init__.py +613 -0
- package/python/foxclaw/skills/hooks_spec.py +73 -0
- package/python/foxclaw/skills/lifecycle.py +278 -0
- package/python/foxclaw/skills/markdown_skill.py +174 -0
- package/python/foxclaw/skills/markdown_store.py +39 -0
- package/python/foxclaw/skills/mcp_client.py +190 -0
- package/python/foxclaw/skills/mcp_store.py +43 -0
- package/python/foxclaw/skills/permission.py +180 -0
- package/python/foxclaw/skills/pipeline.py +386 -0
- package/python/foxclaw/skills/policy.py +80 -0
- package/python/foxclaw/skills/review.py +72 -0
- package/python/foxclaw/skills/store.py +57 -0
- package/python/frontend/assets/core_bg.jpg +0 -0
- package/python/frontend/deck/auth.js +32 -0
- package/python/frontend/deck/chat_model_picker.js +537 -0
- package/python/frontend/deck/domain.js +296 -0
- package/python/frontend/deck/main.js +1950 -0
- package/python/frontend/deck/markdown.js +48 -0
- package/python/frontend/deck/settings.js +324 -0
- package/python/frontend/deck/state.js +6 -0
- package/python/frontend/deck/util.js +6 -0
- package/python/frontend/deck/visuals.js +212 -0
- package/python/frontend/deck.css +855 -0
- package/python/frontend/deck.html +686 -0
- package/python/frontend/deck_v2.html +341 -0
- package/python/frontend/planet/index.html +266 -0
- package/python/frontend/planet/planet.css +579 -0
- package/python/frontend/planet/planet.js +1637 -0
- package/python/frontend/planet/vendor/three.core.min.js +6 -0
- package/python/frontend/planet/vendor/three.module.min.js +6 -0
- package/python/frontend/v3/assets/index-BD7VPbMV.js +33 -0
- package/python/frontend/v3/assets/index-CAvnYWGH.css +1 -0
- package/python/frontend/v3/index.html +15 -0
- package/python/frontend/widget_runtime.js +295 -0
- package/python/frontend/widgets.js +696 -0
- package/python/frontend_src/index.html +14 -0
- package/python/frontend_src/package-lock.json +1376 -0
- package/python/frontend_src/package.json +19 -0
- package/python/frontend_src/src/App.vue +62 -0
- package/python/frontend_src/src/api.js +89 -0
- package/python/frontend_src/src/components/ChatDock.vue +377 -0
- package/python/frontend_src/src/components/ComposerMenu.vue +75 -0
- package/python/frontend_src/src/components/DocViewer.vue +171 -0
- package/python/frontend_src/src/components/Inspector.vue +241 -0
- package/python/frontend_src/src/components/LeftRail.vue +394 -0
- package/python/frontend_src/src/components/MenuPopover.vue +130 -0
- package/python/frontend_src/src/components/MessageStream.vue +401 -0
- package/python/frontend_src/src/components/ModelPicker.vue +355 -0
- package/python/frontend_src/src/components/QuickIngest.vue +118 -0
- package/python/frontend_src/src/components/Stage.vue +226 -0
- package/python/frontend_src/src/components/ToolMenu.vue +144 -0
- package/python/frontend_src/src/components/TopBar.vue +90 -0
- package/python/frontend_src/src/components/panels/ActivityPanel.vue +84 -0
- package/python/frontend_src/src/components/panels/AgentsPanel.vue +86 -0
- package/python/frontend_src/src/components/panels/KnowledgePanel.vue +441 -0
- package/python/frontend_src/src/components/panels/MemoryPanel.vue +118 -0
- package/python/frontend_src/src/components/panels/PanelBox.vue +51 -0
- package/python/frontend_src/src/components/panels/ReviewPanel.vue +308 -0
- package/python/frontend_src/src/components/panels/SettingsPanel.vue +254 -0
- package/python/frontend_src/src/components/panels/TasksPanel.vue +74 -0
- package/python/frontend_src/src/components/panels/ToolsPanel.vue +640 -0
- package/python/frontend_src/src/components/panels/UsagePanel.vue +105 -0
- package/python/frontend_src/src/lib/fmt.js +48 -0
- package/python/frontend_src/src/lib/md.js +204 -0
- package/python/frontend_src/src/main.js +7 -0
- package/python/frontend_src/src/stores/app.js +106 -0
- package/python/frontend_src/src/stores/chat.js +484 -0
- package/python/frontend_src/src/stores/model.js +104 -0
- package/python/frontend_src/src/stores/panels.js +330 -0
- package/python/frontend_src/src/styles/base.css +138 -0
- package/python/frontend_src/src/styles/panel.css +117 -0
- package/python/frontend_src/src/styles/tokens.css +78 -0
- package/python/frontend_src/vite.config.js +46 -0
- package/python/pyproject.toml +265 -0
- package/python/skills/README.md +123 -0
- package/python/skills/execution-contract/SKILL.md +30 -0
- package/python/skills/general-assistant/SKILL.md +34 -0
- package/python/skills/planner/SKILL.md +33 -0
- package/python/skills/schedule-itinerary/SKILL.md +35 -0
- package/python/skills/skill-composition/SKILL.md +31 -0
- package/python/skills/skill-guard/SKILL.md +67 -0
- package/python/skills/skill-memory/SKILL.md +50 -0
- package/python/skills/skill-router/SKILL.md +35 -0
- package/python/tests/conftest.py +76 -0
- package/python/tests/run_all.py +263 -0
- package/python/tests/test_agent_lifecycle.py +360 -0
- package/python/tests/test_ahs_p2.py +414 -0
- package/python/tests/test_anthropic_tools.py +206 -0
- package/python/tests/test_api.py +87 -0
- package/python/tests/test_api_auth.py +83 -0
- package/python/tests/test_api_host_guard.py +69 -0
- package/python/tests/test_attachments.py +167 -0
- package/python/tests/test_audit_chain.py +121 -0
- package/python/tests/test_audit_sink.py +136 -0
- package/python/tests/test_browser.py +153 -0
- package/python/tests/test_browser_request_guard.py +184 -0
- package/python/tests/test_capabilities.py +158 -0
- package/python/tests/test_channel_signing.py +192 -0
- package/python/tests/test_channel_trust.py +109 -0
- package/python/tests/test_channels.py +184 -0
- package/python/tests/test_cli.py +46 -0
- package/python/tests/test_compaction_toolpair.py +119 -0
- package/python/tests/test_config_layering.py +65 -0
- package/python/tests/test_confirm_nonce.py +197 -0
- package/python/tests/test_context_compaction_wiring.py +130 -0
- package/python/tests/test_dispatch.py +95 -0
- package/python/tests/test_domain_evals.py +403 -0
- package/python/tests/test_domain_import.py +78 -0
- package/python/tests/test_domain_reasoners.py +148 -0
- package/python/tests/test_e2e.py +178 -0
- package/python/tests/test_emb_cache.py +107 -0
- package/python/tests/test_embedding_singleton.py +89 -0
- package/python/tests/test_envfile.py +83 -0
- package/python/tests/test_evals_smoke.py +114 -0
- package/python/tests/test_event_spine.py +182 -0
- package/python/tests/test_evidence_semantic.py +101 -0
- package/python/tests/test_evidence_sse.py +97 -0
- package/python/tests/test_file_ingest.py +146 -0
- package/python/tests/test_finance.py +153 -0
- package/python/tests/test_finance_ledger.py +252 -0
- package/python/tests/test_finance_persist.py +178 -0
- package/python/tests/test_gateway.py +144 -0
- package/python/tests/test_governance.py +468 -0
- package/python/tests/test_governance_audit.py +359 -0
- package/python/tests/test_governance_middleware.py +143 -0
- package/python/tests/test_hkc.py +286 -0
- package/python/tests/test_hkc_index_build_manager.py +339 -0
- package/python/tests/test_hkc_manifest_reuse.py +317 -0
- package/python/tests/test_hkc_search_event_sync.py +533 -0
- package/python/tests/test_import_path_guard.py +161 -0
- package/python/tests/test_injection_guard.py +211 -0
- package/python/tests/test_integration.py +141 -0
- package/python/tests/test_itinerary.py +103 -0
- package/python/tests/test_kee_semantic.py +89 -0
- package/python/tests/test_kernel.py +222 -0
- package/python/tests/test_learning.py +110 -0
- package/python/tests/test_llm_admin.py +160 -0
- package/python/tests/test_llm_planner.py +366 -0
- package/python/tests/test_markdown_skills.py +73 -0
- package/python/tests/test_markdown_skills_openclaw.py +71 -0
- package/python/tests/test_mcp_connectors.py +109 -0
- package/python/tests/test_mcp_guardian_discovery.py +91 -0
- package/python/tests/test_mcp_no_memory.py +43 -0
- package/python/tests/test_mcp_policy_gate.py +77 -0
- package/python/tests/test_mcp_server.py +95 -0
- package/python/tests/test_memory_recall.py +95 -0
- package/python/tests/test_metrics.py +66 -0
- package/python/tests/test_multi_chain.py +102 -0
- package/python/tests/test_multimodal.py +135 -0
- package/python/tests/test_negotiation.py +146 -0
- package/python/tests/test_orchestration.py +119 -0
- package/python/tests/test_orchestration_decoupled.py +109 -0
- package/python/tests/test_p3_p5_hardening.py +338 -0
- package/python/tests/test_parallel_dispatch.py +215 -0
- package/python/tests/test_pipeline.py +533 -0
- package/python/tests/test_plan_visible.py +86 -0
- package/python/tests/test_planner.py +95 -0
- package/python/tests/test_policy_gate.py +109 -0
- package/python/tests/test_reasoner.py +185 -0
- package/python/tests/test_release_check.py +263 -0
- package/python/tests/test_resume_checkpoint.py +156 -0
- package/python/tests/test_routing.py +95 -0
- package/python/tests/test_scheduler.py +141 -0
- package/python/tests/test_search.py +204 -0
- package/python/tests/test_secrets.py +159 -0
- package/python/tests/test_semantic.py +78 -0
- package/python/tests/test_sessions.py +91 -0
- package/python/tests/test_settings.py +281 -0
- package/python/tests/test_shadow_learning.py +330 -0
- package/python/tests/test_shared_write.py +207 -0
- package/python/tests/test_skill_taint_gate.py +154 -0
- package/python/tests/test_skills.py +133 -0
- package/python/tests/test_stats_and_events.py +165 -0
- package/python/tests/test_streaming.py +60 -0
- package/python/tests/test_supervisor_pipeline.py +177 -0
- package/python/tests/test_supervisor_triage.py +108 -0
- package/python/tests/test_taint.py +117 -0
- package/python/tests/test_task_stream.py +85 -0
- package/python/tests/test_thinking_sse.py +67 -0
- package/python/tests/test_thinking_stream.py +76 -0
- package/python/tests/test_tool_center.py +129 -0
- package/python/tests/test_tool_parallel.py +113 -0
- package/python/tests/test_tool_params.py +103 -0
- package/python/tests/test_tool_use.py +242 -0
- package/python/tests/test_toplevel_concurrency.py +117 -0
- package/python/tests/test_tracing.py +290 -0
- package/python/tests/test_truth_crystallizer.py +127 -0
- package/python/tests/test_truth_flow.py +93 -0
- package/python/tests/test_url_policy.py +53 -0
- package/python/tests/test_verify_evidence.py +225 -0
- package/python/tests/test_version_sync.py +71 -0
- package/python/tests/test_web_trigger.py +99 -0
- package/python/tools/check_faiss_type.py +31 -0
- package/python/tools/check_log.ps1 +46 -0
- package/python/tools/ivf_status.py +72 -0
- package/python/tools/mypy_baseline.txt +5 -0
- package/python/tools/mypy_ratchet.py +97 -0
- package/python/tools/pack.py +178 -0
- package/python/tools/release_check.py +349 -0
- package/python/tools/restart_foxclaw.ps1 +74 -0
- package/python/tools/shared_write_audit.py +204 -0
- package/python/tools/size_baseline.txt +28 -0
- package/python/tools/size_check.py +102 -0
- package/python/tools/verify_env.bat +2 -0
- package/python/tools/verify_env.py +25 -0
- package/python/vendor/HMR_LICENSE +37 -0
- package/python/vendor/HMR_README.md +65 -0
- package/python/vendor/hkc/LICENSE +37 -0
- package/python/vendor/hkc/hkc_ace/__init__.py +0 -0
- package/python/vendor/hkc/hkc_ace/ace.py +457 -0
- package/python/vendor/hkc/hkc_ace/skill_taxonomy.json +465 -0
- package/python/vendor/hkc/hkc_api/__init__.py +0 -0
- package/python/vendor/hkc/hkc_api/container.py +416 -0
- package/python/vendor/hkc/hkc_api/ingest_jobs.py +103 -0
- package/python/vendor/hkc/hkc_api/main.py +157 -0
- package/python/vendor/hkc/hkc_api/routes/__init__.py +0 -0
- package/python/vendor/hkc/hkc_api/routes/ability.py +151 -0
- package/python/vendor/hkc/hkc_api/routes/config.py +51 -0
- package/python/vendor/hkc/hkc_api/routes/knowledge.py +630 -0
- package/python/vendor/hkc/hkc_api/routes/search.py +88 -0
- package/python/vendor/hkc/hkc_api/schemas.py +153 -0
- package/python/vendor/hkc/hkc_api/synthesis.py +179 -0
- package/python/vendor/hkc/hkc_core/__init__.py +0 -0
- package/python/vendor/hkc/hkc_core/graph/__init__.py +0 -0
- package/python/vendor/hkc/hkc_core/graph/base.py +188 -0
- package/python/vendor/hkc/hkc_core/graph/sqlite_store.py +789 -0
- package/python/vendor/hkc/hkc_core/models/__init__.py +0 -0
- package/python/vendor/hkc/hkc_core/models/enums.py +65 -0
- package/python/vendor/hkc/hkc_core/models/ku.py +307 -0
- package/python/vendor/hkc/hkc_core/utils/__init__.py +0 -0
- package/python/vendor/hkc/hkc_core/utils/id_gen.py +113 -0
- package/python/vendor/hkc/hkc_crystallizer/__init__.py +44 -0
- package/python/vendor/hkc/hkc_crystallizer/adapters.py +94 -0
- package/python/vendor/hkc/hkc_crystallizer/candidate.py +145 -0
- package/python/vendor/hkc/hkc_crystallizer/crystallizer.py +179 -0
- package/python/vendor/hkc/hkc_crystallizer/ingress.py +90 -0
- package/python/vendor/hkc/hkc_kde/__init__.py +0 -0
- package/python/vendor/hkc/hkc_kde/chunker.py +197 -0
- package/python/vendor/hkc/hkc_kde/extractor.py +623 -0
- package/python/vendor/hkc/hkc_kde/kde.py +298 -0
- package/python/vendor/hkc/hkc_kde/loaders/__init__.py +0 -0
- package/python/vendor/hkc/hkc_kde/loaders/ebook_loader.py +153 -0
- package/python/vendor/hkc/hkc_kde/loaders/office_loader.py +194 -0
- package/python/vendor/hkc/hkc_kde/loaders/pdf_loader.py +162 -0
- package/python/vendor/hkc/hkc_kde/loaders/text_loader.py +157 -0
- package/python/vendor/hkc/hkc_kde/loaders/web_loader.py +91 -0
- package/python/vendor/hkc/hkc_kde/models.py +74 -0
- package/python/vendor/hkc/hkc_kde/packager.py +329 -0
- package/python/vendor/hkc/hkc_kde/relation_disc.py +151 -0
- package/python/vendor/hkc/hkc_kee/__init__.py +0 -0
- package/python/vendor/hkc/hkc_kee/dedup.py +227 -0
- package/python/vendor/hkc/hkc_kee/fingerprint.py +106 -0
- package/python/vendor/hkc/hkc_kee/kee.py +541 -0
- package/python/vendor/hkc/hkc_kep/__init__.py +0 -0
- package/python/vendor/hkc/hkc_kep/event_bus.py +205 -0
- package/python/vendor/hkc/hkc_sdk/__init__.py +63 -0
- package/python/vendor/hkc/hkc_sdk/base.py +151 -0
- package/python/vendor/hkc/hkc_sdk/direct_client.py +153 -0
- package/python/vendor/hkc/hkc_sdk/exceptions.py +39 -0
- package/python/vendor/hkc/hkc_sdk/http_client.py +166 -0
- package/python/vendor/hkc/hkc_sdk/models.py +171 -0
- package/python/vendor/hkc/hkc_search/__init__.py +0 -0
- package/python/vendor/hkc/hkc_search/bm25.py +325 -0
- package/python/vendor/hkc/hkc_search/embedding_backends.py +374 -0
- package/python/vendor/hkc/hkc_search/graph_search.py +132 -0
- package/python/vendor/hkc/hkc_search/hybrid.py +331 -0
- package/python/vendor/hkc/hkc_search/index_build_manager.py +378 -0
- package/python/vendor/hkc/hkc_search/vector_search.py +484 -0
- package/python/vendor/hmr/__init__.py +0 -0
- package/python/vendor/hmr/core/__init__.py +0 -0
- package/python/vendor/hmr/core/hmr.py +684 -0
- package/python/vendor/hmr/core/models.py +310 -0
- package/python/vendor/hmr/engines/__init__.py +0 -0
- package/python/vendor/hmr/engines/evolution.py +710 -0
- package/python/vendor/hmr/engines/jit_compiler.py +472 -0
- package/python/vendor/hmr/engines/lifecycle.py +264 -0
- package/python/vendor/hmr/engines/policy.py +625 -0
- package/python/vendor/hmr/engines/recall.py +260 -0
- package/python/vendor/hmr/engines/runtime_state.py +158 -0
- package/python/vendor/hmr/engines/scheduler.py +323 -0
- package/python/vendor/hmr/engines/semantic.py +150 -0
- package/python/vendor/hmr/engines/temporal.py +261 -0
- package/python/vendor/hmr/engines/thought_chain.py +635 -0
- package/python/vendor/hmr/graph/__init__.py +0 -0
- package/python/vendor/hmr/graph/cwg.py +338 -0
- package/python/vendor/hmr/graph/memory_graph.py +530 -0
- package/python/vendor/hmr/storage/__init__.py +0 -0
- package/python/vendor/hmr/storage/memory_fs.py +300 -0
- package/python/vendor/hmr/storage/vector_store.py +520 -0
|
@@ -0,0 +1,696 @@
|
|
|
1
|
+
/* ════════════════════════════════════════════════════════════
|
|
2
|
+
FOXCLAW DECK — Widget Definitions
|
|
3
|
+
每个 widget 是一个 registerWidget() 注册。
|
|
4
|
+
新增模块只需在这里加一个 register block。
|
|
5
|
+
════════════════════════════════════════════════════════════ */
|
|
6
|
+
|
|
7
|
+
/* 共享工具(由主文件注入到 ctx) */
|
|
8
|
+
function _esc(s){return String(s).replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>').replace(/\n/g,'<br>');}
|
|
9
|
+
function _statusColor(s){return{PASS:'#1dffa6',WARN:'#ffb347',BLOCK:'#ff4060',BASELINE:'#b066ff',PENDING:'#3a4d68'}[s]||'#1de9ff';}
|
|
10
|
+
|
|
11
|
+
/* ─────────────────────────────────────────────
|
|
12
|
+
WIDGET 1: AGENT 编队 (roster)
|
|
13
|
+
───────────────────────────────────────────── */
|
|
14
|
+
WidgetRuntime.register({
|
|
15
|
+
id: 'roster',
|
|
16
|
+
title: 'AGENT 编队',
|
|
17
|
+
icon: '◈',
|
|
18
|
+
defaultColumn: 'left',
|
|
19
|
+
size: { flex: true },
|
|
20
|
+
render(el, ctx) {
|
|
21
|
+
el.innerHTML = `<div class="roster" data-role="roster-list"></div>`;
|
|
22
|
+
const list = el.querySelector('[data-role="roster-list"]');
|
|
23
|
+
list.innerHTML = ctx.AGENTS.map(a => `
|
|
24
|
+
<div class="agent-pod ${a.id===ctx.activeAgent?'active':''}" data-pod="${a.id}"
|
|
25
|
+
style="--apc:${a.color}">
|
|
26
|
+
<div class="pod-avatar"><div class="ring-pulse"></div>${a.emoji}</div>
|
|
27
|
+
<div class="pod-info">
|
|
28
|
+
<div class="pod-name">${a.name}</div>
|
|
29
|
+
<div class="pod-role">${a.code} · ${a.role}</div>
|
|
30
|
+
<div class="pod-state"><span class="s-dot"></span><span data-podstate="${a.id}">IDLE</span></div>
|
|
31
|
+
</div>
|
|
32
|
+
<div class="pod-metric">
|
|
33
|
+
<div class="pm-val" data-podtask="${a.id}" style="color:${a.color}">${a.tasks}</div>
|
|
34
|
+
<div class="pm-lbl">TASK</div>
|
|
35
|
+
</div>
|
|
36
|
+
</div>`).join('');
|
|
37
|
+
list.querySelectorAll('[data-pod]').forEach(pod => {
|
|
38
|
+
pod.onclick = () => ctx.setActiveCore(pod.dataset.pod);
|
|
39
|
+
});
|
|
40
|
+
},
|
|
41
|
+
onAgentChange(agentId, el) {
|
|
42
|
+
el.querySelectorAll('.agent-pod').forEach(p =>
|
|
43
|
+
p.classList.toggle('active', p.dataset.pod === agentId));
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
/* ─────────────────────────────────────────────
|
|
48
|
+
WIDGET 2: 任务流 (tasks)
|
|
49
|
+
───────────────────────────────────────────── */
|
|
50
|
+
WidgetRuntime.register({
|
|
51
|
+
id: 'tasks',
|
|
52
|
+
title: '任务流',
|
|
53
|
+
icon: '▤',
|
|
54
|
+
defaultColumn: 'left',
|
|
55
|
+
size: { maxH: 200 },
|
|
56
|
+
render(el, ctx) {
|
|
57
|
+
el.innerHTML = `<div class="tc-stream" data-role="task-stream"><div class="empty">等待指令下达</div></div>`;
|
|
58
|
+
ctx._taskStreamEl = el.querySelector('[data-role="task-stream"]');
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
/* ─────────────────────────────────────────────
|
|
63
|
+
WIDGET 3: 中央核心 (core) — 激活 Agent
|
|
64
|
+
───────────────────────────────────────────── */
|
|
65
|
+
WidgetRuntime.register({
|
|
66
|
+
id: 'core',
|
|
67
|
+
title: '中央核心 · 激活单元',
|
|
68
|
+
icon: '⊚',
|
|
69
|
+
defaultColumn: 'center',
|
|
70
|
+
size: { flex: true },
|
|
71
|
+
render(el, ctx) {
|
|
72
|
+
el.innerHTML = `
|
|
73
|
+
<div class="core-stage" data-role="core-stage">
|
|
74
|
+
<div class="core-hud-tl">SESSION <b data-hud="session">—</b><br>NODES <b data-hud="nodes">0</b></div>
|
|
75
|
+
<div class="core-hud-tr">CONF <b data-hud="conf">—</b><br>Δ DRIFT <b data-hud="drift">—</b></div>
|
|
76
|
+
<div class="core-hud-bl">POLICY <b data-hud="policy">v1</b><br>RULES <b data-hud="rules">0</b></div>
|
|
77
|
+
<div class="core-hud-br">MODE <b data-hud="mode">SHADOW</b><br>BLOCK <b data-hud="block">0.25</b></div>
|
|
78
|
+
<div class="core-orbit">
|
|
79
|
+
<div class="orbit-ring r1"></div><div class="orbit-ring r2"></div><div class="orbit-ring r3"></div>
|
|
80
|
+
<div class="orbit-tick" data-role="orbit-tick"></div>
|
|
81
|
+
<div class="radar-sweep"></div>
|
|
82
|
+
</div>
|
|
83
|
+
<div class="core-avatar" data-role="core-avatar">🏢</div>
|
|
84
|
+
<div class="core-name" data-role="core-name">主管</div>
|
|
85
|
+
<div class="core-role" data-role="core-role">SUPERVISOR · 全局协调</div>
|
|
86
|
+
<div class="core-statusline">
|
|
87
|
+
<span data-role="core-status-text">系统就绪 · 待命中</span>
|
|
88
|
+
<span class="cs-cursor"></span>
|
|
89
|
+
</div>
|
|
90
|
+
<div class="core-telemetry">
|
|
91
|
+
<div class="ct-stat"><div class="cts-val" data-core="tasks">0</div><div class="cts-lbl">任务</div></div>
|
|
92
|
+
<div class="ct-stat"><div class="cts-val" data-core="mem">0</div><div class="cts-lbl">记忆</div></div>
|
|
93
|
+
<div class="ct-stat"><div class="cts-val" data-core="nodes">0</div><div class="cts-lbl">推理</div></div>
|
|
94
|
+
</div>
|
|
95
|
+
<div class="chat-log" data-role="chat-log"></div>
|
|
96
|
+
</div>`;
|
|
97
|
+
// orbit ticks
|
|
98
|
+
const tick = el.querySelector('[data-role="orbit-tick"]');
|
|
99
|
+
let h=''; for(let i=0;i<24;i++)h+=`<span style="transform:translateX(-50%) rotate(${i*15}deg)"></span>`;
|
|
100
|
+
tick.innerHTML=h;
|
|
101
|
+
ctx._coreEl = el;
|
|
102
|
+
},
|
|
103
|
+
onAgentChange(agentId, el, ctx) {
|
|
104
|
+
const a = ctx.AG(agentId);
|
|
105
|
+
el.querySelector('[data-role="core-avatar"]').textContent = a.emoji;
|
|
106
|
+
el.querySelector('[data-role="core-avatar"]').style.setProperty('--cac', a.color);
|
|
107
|
+
el.querySelector('[data-role="core-name"]').textContent = a.name;
|
|
108
|
+
el.querySelector('[data-role="core-role"]').textContent = `${a.code} · ${a.role}`;
|
|
109
|
+
el.querySelector('[data-role="core-status-text"]').style.color = a.color;
|
|
110
|
+
el.querySelector('.cs-cursor').style.background = a.color;
|
|
111
|
+
},
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
/* ─────────────────────────────────────────────
|
|
115
|
+
WIDGET 4: HARNESS 遥测 (harness)
|
|
116
|
+
───────────────────────────────────────────── */
|
|
117
|
+
WidgetRuntime.register({
|
|
118
|
+
id: 'harness',
|
|
119
|
+
title: 'HARNESS 遥测',
|
|
120
|
+
icon: '⛨',
|
|
121
|
+
defaultColumn: 'right',
|
|
122
|
+
size: {},
|
|
123
|
+
events: ['policy_updated', 'shadow_calibrated'],
|
|
124
|
+
render(el) {
|
|
125
|
+
el.innerHTML = `
|
|
126
|
+
<div class="harness-widget">
|
|
127
|
+
<svg class="h-ring-svg" width="72" height="72" viewBox="0 0 72 72">
|
|
128
|
+
<circle class="h-ring-bg" cx="36" cy="36" r="30"/>
|
|
129
|
+
<circle class="h-ring-fg" data-role="h-ring" cx="36" cy="36" r="30" stroke="#ffb347"
|
|
130
|
+
stroke-dasharray="188.5" stroke-dashoffset="188.5"/>
|
|
131
|
+
<text class="h-ring-label" x="36" y="32" fill="#cfe8ff" font-size="16" data-role="h-ring-val">0</text>
|
|
132
|
+
<text class="h-ring-label" x="36" y="46" fill="#3a4d68" font-size="8">/ 20</text>
|
|
133
|
+
</svg>
|
|
134
|
+
<div class="h-info">
|
|
135
|
+
<span class="h-mode shadow" data-role="h-mode">◔ SHADOW 校准</span>
|
|
136
|
+
<div class="h-detail">
|
|
137
|
+
BLOCK 阈值 <b data-role="h-block">0.250</b><br>
|
|
138
|
+
WARN 阈值 <b data-role="h-warn">0.150</b><br>
|
|
139
|
+
Δ 均值 <b data-role="h-avg">—</b>
|
|
140
|
+
</div>
|
|
141
|
+
</div>
|
|
142
|
+
</div>
|
|
143
|
+
<div class="weight-section">
|
|
144
|
+
<div class="wt-row"><span class="wt-lbl">语义距离</span><div class="wt-track"><div class="wt-fill" data-role="wt-sem" style="width:50%;background:#1de9ff;color:#1de9ff"></div></div><span class="wt-pct" data-role="wt-sem-pct">50%</span></div>
|
|
145
|
+
<div class="wt-row"><span class="wt-lbl">工具意图</span><div class="wt-track"><div class="wt-fill" data-role="wt-tool" style="width:30%;background:#b066ff;color:#b066ff"></div></div><span class="wt-pct" data-role="wt-tool-pct">30%</span></div>
|
|
146
|
+
<div class="wt-row"><span class="wt-lbl">范围蔓延</span><div class="wt-track"><div class="wt-fill" data-role="wt-scope" style="width:20%;background:#ffb347;color:#ffb347"></div></div><span class="wt-pct" data-role="wt-scope-pct">20%</span></div>
|
|
147
|
+
</div>`;
|
|
148
|
+
},
|
|
149
|
+
refresh(el, ctx, agentId) {
|
|
150
|
+
ctx.loadHarnessInto(el, agentId);
|
|
151
|
+
},
|
|
152
|
+
onEvent(evt, el, ctx) {
|
|
153
|
+
// policy 更新或校准完成时立即刷新
|
|
154
|
+
ctx.loadHarnessInto(el, ctx.activeAgent);
|
|
155
|
+
},
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
/* ─────────────────────────────────────────────
|
|
159
|
+
WIDGET 5: 推理链 STREAM (thoughtchain)
|
|
160
|
+
───────────────────────────────────────────── */
|
|
161
|
+
WidgetRuntime.register({
|
|
162
|
+
id: 'thoughtchain',
|
|
163
|
+
title: '推理链 STREAM',
|
|
164
|
+
icon: '⌬',
|
|
165
|
+
defaultColumn: 'right',
|
|
166
|
+
size: { flex: true },
|
|
167
|
+
render(el) {
|
|
168
|
+
el.innerHTML = `<div class="tc-stream" data-role="tc-stream"><div class="empty">执行任务后显示推理轨迹</div></div>`;
|
|
169
|
+
},
|
|
170
|
+
refresh(el, ctx, agentId) {
|
|
171
|
+
ctx.loadChainInto(el, agentId);
|
|
172
|
+
},
|
|
173
|
+
onAgentChange(agentId, el, ctx) {
|
|
174
|
+
ctx.loadChainInto(el, agentId);
|
|
175
|
+
},
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
/* ─────────────────────────────────────────────
|
|
179
|
+
WIDGET 6: 事件流 LIVE (events)
|
|
180
|
+
───────────────────────────────────────────── */
|
|
181
|
+
WidgetRuntime.register({
|
|
182
|
+
id: 'events',
|
|
183
|
+
title: '事件流 · LIVE',
|
|
184
|
+
icon: '⚡',
|
|
185
|
+
defaultColumn: 'right',
|
|
186
|
+
size: { maxH: 180 },
|
|
187
|
+
events: ['harness_block', 'harness_warn', 'policy_updated', 'shadow_calibrated'],
|
|
188
|
+
render(el) {
|
|
189
|
+
el.innerHTML = `<div class="evt-feed" data-role="evt-feed"><div class="empty">监听 Harness 事件...</div></div>`;
|
|
190
|
+
},
|
|
191
|
+
onEvent(evt, el) {
|
|
192
|
+
const feed = el.querySelector('[data-role="evt-feed"]');
|
|
193
|
+
feed.querySelector('.empty')?.remove();
|
|
194
|
+
const cmap={harness_block:'#ff4060',harness_warn:'#ffb347',policy_updated:'#b066ff',shadow_calibrated:'#1dffa6'};
|
|
195
|
+
const color = cmap[evt.type] || '#1de9ff';
|
|
196
|
+
const d = evt.data || {};
|
|
197
|
+
const reason = d.result?.reason || d.rule_id || d.reason || '';
|
|
198
|
+
const item = document.createElement('div');
|
|
199
|
+
item.className = 'evt'; item.style.setProperty('--ec', color);
|
|
200
|
+
item.innerHTML = `
|
|
201
|
+
<div class="evt-top"><span class="evt-type">${evt.type.replace('harness_','').replace('_',' ')}</span>
|
|
202
|
+
<span class="evt-time">${new Date().toLocaleTimeString('en-GB')}</span></div>
|
|
203
|
+
<div class="evt-body">${_esc((d.agent_id||'—')+' · '+reason).slice(0,70)}</div>`;
|
|
204
|
+
feed.insertBefore(item, feed.firstChild);
|
|
205
|
+
while (feed.children.length > 20) feed.lastChild?.remove();
|
|
206
|
+
},
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
/* ─────────────────────────────────────────────
|
|
210
|
+
WIDGET 7: 协同 DAG (dag) — 多 Agent 星舰控制流
|
|
211
|
+
命令 → 主管分发 → 子 Agent → Harness 关卡 → 记忆汇聚
|
|
212
|
+
───────────────────────────────────────────── */
|
|
213
|
+
WidgetRuntime.register({
|
|
214
|
+
id: 'dag',
|
|
215
|
+
title: '协同 DAG · 控制流',
|
|
216
|
+
icon: '⊶',
|
|
217
|
+
defaultColumn: 'center',
|
|
218
|
+
size: { maxH: 260 },
|
|
219
|
+
events: ['harness_block', 'harness_warn', 'policy_updated'],
|
|
220
|
+
render(el, ctx) {
|
|
221
|
+
el.innerHTML = `
|
|
222
|
+
<div class="dag-wrap">
|
|
223
|
+
<svg class="dag-svg" viewBox="0 0 640 230" preserveAspectRatio="xMidYMid meet">
|
|
224
|
+
<defs>
|
|
225
|
+
<marker id="dagArrow" viewBox="0 0 10 10" refX="8" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse">
|
|
226
|
+
<path d="M2 1L8 5L2 9" fill="none" stroke="#3a4d68" stroke-width="1.5" stroke-linecap="round"/>
|
|
227
|
+
</marker>
|
|
228
|
+
</defs>
|
|
229
|
+
<g data-role="dag-edges"></g>
|
|
230
|
+
<g data-role="dag-nodes"></g>
|
|
231
|
+
</svg>
|
|
232
|
+
</div>`;
|
|
233
|
+
ctx._dagEl = el;
|
|
234
|
+
_dagBuild(el, ctx);
|
|
235
|
+
},
|
|
236
|
+
onAgentChange(agentId, el, ctx) {
|
|
237
|
+
_dagSetActive(el, agentId);
|
|
238
|
+
},
|
|
239
|
+
onEvent(evt, el, ctx) {
|
|
240
|
+
if (evt.type === 'harness_block') _dagFlashGate(el, '#ff4060');
|
|
241
|
+
else if (evt.type === 'harness_warn') _dagFlashGate(el, '#ffb347');
|
|
242
|
+
else if (evt.type === 'policy_updated') _dagFlashGate(el, '#b066ff');
|
|
243
|
+
},
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
/* DAG 拓扑定义 */
|
|
247
|
+
const _DAG_NODES = {
|
|
248
|
+
command: { x: 60, y: 115, label: '指令', icon: '❯', kind: 'entry', color: '#1de9ff' },
|
|
249
|
+
supervisor: { x: 180, y: 115, label: '主管', icon: '🏢', kind: 'hub', color: '#1de9ff' },
|
|
250
|
+
assistant: { x: 320, y: 35, label: '助手', icon: '🤝', kind: 'agent', color: '#4d9fff' },
|
|
251
|
+
finance: { x: 320, y: 90, label: '财务', icon: '💰', kind: 'agent', color: '#ffb347' },
|
|
252
|
+
admin: { x: 320, y: 145, label: '行政', icon: '📅', kind: 'agent', color: '#ff5e9c' },
|
|
253
|
+
office: { x: 320, y: 200, label: '办公', icon: '📚', kind: 'agent', color: '#1dffa6' },
|
|
254
|
+
harness: { x: 460, y: 115, label: 'HARNESS', icon: '⛨', kind: 'gate', color: '#b066ff' },
|
|
255
|
+
memory: { x: 580, y: 115, label: 'HMR', icon: '🧠', kind: 'sink', color: '#1dffa6' },
|
|
256
|
+
};
|
|
257
|
+
const _DAG_EDGES = [
|
|
258
|
+
['command','supervisor'],
|
|
259
|
+
['supervisor','assistant'],['supervisor','finance'],['supervisor','admin'],['supervisor','office'],
|
|
260
|
+
['assistant','harness'],['finance','harness'],['admin','harness'],['office','harness'],
|
|
261
|
+
['harness','memory'],['memory','supervisor'],
|
|
262
|
+
];
|
|
263
|
+
|
|
264
|
+
function _dagBuild(el, ctx) {
|
|
265
|
+
const edgesG = el.querySelector('[data-role="dag-edges"]');
|
|
266
|
+
const nodesG = el.querySelector('[data-role="dag-nodes"]');
|
|
267
|
+
|
|
268
|
+
// edges
|
|
269
|
+
edgesG.innerHTML = _DAG_EDGES.map(([from, to], i) => {
|
|
270
|
+
const a = _DAG_NODES[from], b = _DAG_NODES[to];
|
|
271
|
+
const curve = (from === 'memory' && to === 'supervisor')
|
|
272
|
+
? `M${a.x},${a.y+18} C${a.x},${a.y+70} ${b.x},${b.y+70} ${b.x},${b.y+18}` // return loop below
|
|
273
|
+
: `M${a.x+16},${a.y} C${(a.x+b.x)/2},${a.y} ${(a.x+b.x)/2},${b.y} ${b.x-16},${b.y}`;
|
|
274
|
+
return `<path class="dag-edge" data-edge="${from}-${to}" d="${curve}"
|
|
275
|
+
fill="none" stroke="#1a2942" stroke-width="1.5" marker-end="url(#dagArrow)"/>`;
|
|
276
|
+
}).join('');
|
|
277
|
+
|
|
278
|
+
// nodes
|
|
279
|
+
nodesG.innerHTML = Object.entries(_DAG_NODES).map(([id, n]) => {
|
|
280
|
+
const r = n.kind === 'hub' ? 17 : n.kind === 'gate' ? 16 : 14;
|
|
281
|
+
const shape = n.kind === 'gate'
|
|
282
|
+
? `<rect class="dag-node-shape" data-node="${id}" x="${n.x-r}" y="${n.y-r}" width="${r*2}" height="${r*2}" rx="3"
|
|
283
|
+
fill="rgba(10,20,40,0.9)" stroke="${n.color}" stroke-width="1.5"/>`
|
|
284
|
+
: `<circle class="dag-node-shape" data-node="${id}" cx="${n.x}" cy="${n.y}" r="${r}"
|
|
285
|
+
fill="rgba(10,20,40,0.9)" stroke="${n.color}" stroke-width="1.5"/>`;
|
|
286
|
+
const lbl = n.kind === 'gate'
|
|
287
|
+
? `<text class="dag-label" x="${n.x}" y="${n.y+r+11}" fill="${n.color}" font-size="8" text-anchor="middle">${n.label}</text>`
|
|
288
|
+
: `<text class="dag-label" x="${n.x}" y="${n.y+r+11}" fill="#6b88aa" font-size="9" text-anchor="middle">${n.label}</text>`;
|
|
289
|
+
return `<g class="dag-node" data-node-g="${id}" style="--dnc:${n.color}">
|
|
290
|
+
${shape}
|
|
291
|
+
<text class="dag-icon" x="${n.x}" y="${n.y+1}" font-size="13" text-anchor="middle" dominant-baseline="central">${n.icon}</text>
|
|
292
|
+
${lbl}
|
|
293
|
+
</g>`;
|
|
294
|
+
}).join('');
|
|
295
|
+
|
|
296
|
+
_dagSetActive(el, ctx.activeAgent);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
function _dagSetActive(el, agentId) {
|
|
300
|
+
if (!el) return;
|
|
301
|
+
el.querySelectorAll('.dag-node').forEach(g => {
|
|
302
|
+
g.classList.toggle('dag-dim', false);
|
|
303
|
+
});
|
|
304
|
+
// highlight active agent path: command→supervisor→agent→harness→memory
|
|
305
|
+
const path = ['command','supervisor', agentId, 'harness','memory'];
|
|
306
|
+
el.querySelectorAll('.dag-node').forEach(g => {
|
|
307
|
+
const id = g.dataset.nodeG;
|
|
308
|
+
g.classList.toggle('dag-active', path.includes(id));
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
let _dagAnimSeq = 0;
|
|
313
|
+
function _dagPulse(el, agentId) {
|
|
314
|
+
if (!el) return;
|
|
315
|
+
_dagAnimSeq++;
|
|
316
|
+
const seq = _dagAnimSeq;
|
|
317
|
+
const flow = [
|
|
318
|
+
['command-supervisor', 'command', 'supervisor'],
|
|
319
|
+
[`supervisor-${agentId}`, agentId, null],
|
|
320
|
+
[`${agentId}-harness`, 'harness', null],
|
|
321
|
+
['harness-memory', 'memory', null],
|
|
322
|
+
['memory-supervisor', null, null],
|
|
323
|
+
];
|
|
324
|
+
let i = 0;
|
|
325
|
+
const step = () => {
|
|
326
|
+
if (seq !== _dagAnimSeq) return; // 被新动画打断
|
|
327
|
+
if (i >= flow.length) { _dagClearFlow(el); return; }
|
|
328
|
+
const [edgeId, nodeId] = flow[i];
|
|
329
|
+
const edge = el.querySelector(`[data-edge="${edgeId}"]`);
|
|
330
|
+
if (edge) {
|
|
331
|
+
edge.classList.add('dag-edge-flow');
|
|
332
|
+
setTimeout(() => edge.classList.remove('dag-edge-flow'), 700);
|
|
333
|
+
}
|
|
334
|
+
if (nodeId) {
|
|
335
|
+
const node = el.querySelector(`[data-node-g="${nodeId}"]`);
|
|
336
|
+
if (node) {
|
|
337
|
+
node.classList.add('dag-pulse');
|
|
338
|
+
setTimeout(() => node.classList.remove('dag-pulse'), 700);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
i++;
|
|
342
|
+
setTimeout(step, 280);
|
|
343
|
+
};
|
|
344
|
+
step();
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
function _dagClearFlow(el) {
|
|
348
|
+
el.querySelectorAll('.dag-edge-flow').forEach(e => e.classList.remove('dag-edge-flow'));
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
function _dagFlashGate(el, color) {
|
|
352
|
+
if (!el) return;
|
|
353
|
+
const gate = el.querySelector('[data-node="harness"]');
|
|
354
|
+
if (!gate) return;
|
|
355
|
+
const g = gate.closest('.dag-node') || gate;
|
|
356
|
+
// 注入一次性 keyframes(如未注入)
|
|
357
|
+
if (!document.getElementById('dag-flash-style')) {
|
|
358
|
+
const st = document.createElement('style');
|
|
359
|
+
st.id = 'dag-flash-style';
|
|
360
|
+
st.textContent = `@keyframes dagGateFlash{
|
|
361
|
+
0%{stroke-width:1.5;filter:none}
|
|
362
|
+
25%{stroke-width:4;filter:drop-shadow(0 0 14px var(--flash-c))}
|
|
363
|
+
60%{stroke-width:3;filter:drop-shadow(0 0 10px var(--flash-c))}
|
|
364
|
+
100%{stroke-width:1.5;filter:none}}
|
|
365
|
+
.dag-gate-flash{animation:dagGateFlash 1.2s ease-out;transform-box:fill-box;transform-origin:center}`;
|
|
366
|
+
document.head.appendChild(st);
|
|
367
|
+
}
|
|
368
|
+
const orig = gate.getAttribute('stroke');
|
|
369
|
+
gate.style.setProperty('--flash-c', color);
|
|
370
|
+
gate.setAttribute('stroke', color);
|
|
371
|
+
gate.classList.remove('dag-gate-flash');
|
|
372
|
+
void gate.offsetWidth; // 强制重排,允许动画重放
|
|
373
|
+
gate.classList.add('dag-gate-flash');
|
|
374
|
+
// 同时让 HARNESS 文字标签也闪一下
|
|
375
|
+
const label = el.querySelector('.dag-node[data-node-g="harness"] .dag-label');
|
|
376
|
+
if (label) { label.style.fill = color; label.style.fontWeight = '700'; }
|
|
377
|
+
setTimeout(() => {
|
|
378
|
+
gate.setAttribute('stroke', orig);
|
|
379
|
+
gate.classList.remove('dag-gate-flash');
|
|
380
|
+
if (label) { label.style.fill = ''; label.style.fontWeight = ''; }
|
|
381
|
+
}, 1200);
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
/* ─────────────────────────────────────────────
|
|
385
|
+
WIDGET 8: 执行终端 (terminal) — Shell 执行流
|
|
386
|
+
命令回显 · 记忆检索 · 推理 · 工具调用 · Harness 校验
|
|
387
|
+
带打字机流式效果,营造 "AI 正在工作" 的真实感
|
|
388
|
+
───────────────────────────────────────────── */
|
|
389
|
+
WidgetRuntime.register({
|
|
390
|
+
id: 'terminal',
|
|
391
|
+
title: '执行终端 · SHELL',
|
|
392
|
+
icon: '▩',
|
|
393
|
+
defaultColumn: 'left',
|
|
394
|
+
size: { maxH: 240, flex: false },
|
|
395
|
+
render(el, ctx) {
|
|
396
|
+
el.innerHTML = `
|
|
397
|
+
<div class="term">
|
|
398
|
+
<div class="term-out" data-role="term-out"></div>
|
|
399
|
+
<div class="term-prompt-line">
|
|
400
|
+
<span class="term-ps">foxclaw@deck</span><span class="term-ps-sep">:</span><span class="term-ps-path" data-role="term-agent">~/supervisor</span><span class="term-ps-dollar">$</span>
|
|
401
|
+
<span class="term-caret"></span>
|
|
402
|
+
</div>
|
|
403
|
+
</div>`;
|
|
404
|
+
ctx._terminalEl = el;
|
|
405
|
+
ctx.termLog = (line, type) => _termWrite(el, line, type);
|
|
406
|
+
ctx.termClear = () => { el.querySelector('[data-role="term-out"]').innerHTML = ''; };
|
|
407
|
+
_termBoot(el);
|
|
408
|
+
},
|
|
409
|
+
onAgentChange(agentId, el, ctx) {
|
|
410
|
+
const a = ctx.AG(agentId);
|
|
411
|
+
const ps = el.querySelector('[data-role="term-agent"]');
|
|
412
|
+
if (ps) ps.textContent = `~/${agentId}`;
|
|
413
|
+
_termWrite(el, `切换激活单元 → ${a.name} [${a.code}]`, 'info');
|
|
414
|
+
},
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
function _termBoot(el) {
|
|
418
|
+
const lines = [
|
|
419
|
+
['FOXCLAW DECK · 执行终端 v1.0', 'info'],
|
|
420
|
+
['初始化 HMR 认知运行时...', 'out'],
|
|
421
|
+
['挂载记忆层 [Vector · Graph · KV]', 'ok'],
|
|
422
|
+
['Harness 线束在线 · Shadow 校准模式', 'ok'],
|
|
423
|
+
['五单元编队就绪 · 等待指令', 'info'],
|
|
424
|
+
];
|
|
425
|
+
let i = 0;
|
|
426
|
+
const tick = () => {
|
|
427
|
+
if (i >= lines.length) return;
|
|
428
|
+
_termWrite(el, lines[i][0], lines[i][1]);
|
|
429
|
+
i++; setTimeout(tick, 220);
|
|
430
|
+
};
|
|
431
|
+
tick();
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
function _termWrite(el, text, type = 'out', stream = false) {
|
|
435
|
+
const out = el.querySelector('[data-role="term-out"]');
|
|
436
|
+
if (!out) return;
|
|
437
|
+
const prefix = {
|
|
438
|
+
cmd: '❯ ',
|
|
439
|
+
info: '◇ ',
|
|
440
|
+
ok: '✓ ',
|
|
441
|
+
warn: '▲ ',
|
|
442
|
+
err: '✕ ',
|
|
443
|
+
tool: '⚙ ',
|
|
444
|
+
out: ' ',
|
|
445
|
+
}[type] || ' ';
|
|
446
|
+
const line = document.createElement('div');
|
|
447
|
+
line.className = `term-line tl-${type}`;
|
|
448
|
+
const ts = new Date().toLocaleTimeString('en-GB');
|
|
449
|
+
line.innerHTML = `<span class="tl-ts">${ts}</span><span class="tl-pfx">${prefix}</span><span class="tl-txt"></span>`;
|
|
450
|
+
out.appendChild(line);
|
|
451
|
+
const txtEl = line.querySelector('.tl-txt');
|
|
452
|
+
|
|
453
|
+
if (stream) {
|
|
454
|
+
let j = 0;
|
|
455
|
+
const speed = 14;
|
|
456
|
+
const type_ = () => {
|
|
457
|
+
txtEl.textContent = text.slice(0, j);
|
|
458
|
+
j++;
|
|
459
|
+
out.scrollTop = out.scrollHeight;
|
|
460
|
+
if (j <= text.length) setTimeout(type_, speed);
|
|
461
|
+
};
|
|
462
|
+
type_();
|
|
463
|
+
} else {
|
|
464
|
+
txtEl.textContent = text;
|
|
465
|
+
}
|
|
466
|
+
out.scrollTop = out.scrollHeight;
|
|
467
|
+
// 限制行数
|
|
468
|
+
while (out.children.length > 80) out.firstChild?.remove();
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
/* ─────────────────────────────────────────────
|
|
472
|
+
WIDGET 9: AI 浏览器 (browser) — 网页操作可视化
|
|
473
|
+
模拟 Agent 浏览网页:地址栏 · 加载流 · 操作高亮(点击/输入/滚动)
|
|
474
|
+
───────────────────────────────────────────── */
|
|
475
|
+
WidgetRuntime.register({
|
|
476
|
+
id: 'browser',
|
|
477
|
+
title: 'AI 浏览器 · BROWSE',
|
|
478
|
+
icon: '◍',
|
|
479
|
+
defaultColumn: 'center',
|
|
480
|
+
size: { maxH: 300, flex: false },
|
|
481
|
+
render(el, ctx) {
|
|
482
|
+
el.innerHTML = `
|
|
483
|
+
<div class="brz">
|
|
484
|
+
<div class="brz-bar">
|
|
485
|
+
<div class="brz-dots"><span></span><span></span><span></span></div>
|
|
486
|
+
<div class="brz-url" data-role="brz-url">about:standby</div>
|
|
487
|
+
<div class="brz-status" data-role="brz-status">IDLE</div>
|
|
488
|
+
</div>
|
|
489
|
+
<div class="brz-progress" data-role="brz-progress"></div>
|
|
490
|
+
<div class="brz-viewport" data-role="brz-viewport">
|
|
491
|
+
<div class="brz-empty">浏览器待命 · 等待 Agent 导航指令</div>
|
|
492
|
+
</div>
|
|
493
|
+
</div>`;
|
|
494
|
+
ctx._browserEl = el;
|
|
495
|
+
ctx.browseTo = (url, actions) => _brzNavigate(el, url, actions);
|
|
496
|
+
},
|
|
497
|
+
});
|
|
498
|
+
|
|
499
|
+
function _brzNavigate(el, url, actions) {
|
|
500
|
+
const urlEl = el.querySelector('[data-role="brz-url"]');
|
|
501
|
+
const statusEl = el.querySelector('[data-role="brz-status"]');
|
|
502
|
+
const progEl = el.querySelector('[data-role="brz-progress"]');
|
|
503
|
+
const vp = el.querySelector('[data-role="brz-viewport"]');
|
|
504
|
+
if (!vp) return;
|
|
505
|
+
|
|
506
|
+
urlEl.textContent = url;
|
|
507
|
+
statusEl.textContent = 'LOADING';
|
|
508
|
+
statusEl.className = 'brz-status loading';
|
|
509
|
+
|
|
510
|
+
// 进度条动画
|
|
511
|
+
progEl.style.width = '0%';
|
|
512
|
+
progEl.style.opacity = '1';
|
|
513
|
+
setTimeout(() => progEl.style.width = '70%', 80);
|
|
514
|
+
setTimeout(() => { progEl.style.width = '100%'; }, 700);
|
|
515
|
+
setTimeout(() => { progEl.style.opacity = '0'; statusEl.textContent = 'LOADED'; statusEl.className = 'brz-status loaded'; }, 950);
|
|
516
|
+
|
|
517
|
+
// 渲染一个抽象的"网页骨架" + 操作高亮
|
|
518
|
+
vp.innerHTML = `
|
|
519
|
+
<div class="brz-page">
|
|
520
|
+
<div class="brz-skel brz-skel-title"></div>
|
|
521
|
+
<div class="brz-skel brz-skel-nav">
|
|
522
|
+
<span></span><span></span><span></span><span></span>
|
|
523
|
+
</div>
|
|
524
|
+
<div class="brz-hero"></div>
|
|
525
|
+
<div class="brz-skel brz-skel-line w90"></div>
|
|
526
|
+
<div class="brz-skel brz-skel-line w75"></div>
|
|
527
|
+
<div class="brz-skel brz-skel-line w85"></div>
|
|
528
|
+
<div class="brz-cards">
|
|
529
|
+
<div class="brz-card"></div><div class="brz-card"></div><div class="brz-card"></div>
|
|
530
|
+
</div>
|
|
531
|
+
<div class="brz-cursor" data-role="brz-cursor">➤</div>
|
|
532
|
+
</div>`;
|
|
533
|
+
|
|
534
|
+
// AI 操作序列高亮
|
|
535
|
+
const acts = actions || [
|
|
536
|
+
{ type: 'scan', label: '解析页面结构', x: 50, y: 20 },
|
|
537
|
+
{ type: 'click', label: '点击主内容区', x: 30, y: 45 },
|
|
538
|
+
{ type: 'read', label: '提取关键信息', x: 60, y: 65 },
|
|
539
|
+
{ type: 'extract', label: '写入记忆库', x: 50, y: 80 },
|
|
540
|
+
];
|
|
541
|
+
const cursor = vp.querySelector('[data-role="brz-cursor"]');
|
|
542
|
+
let i = 0;
|
|
543
|
+
const runAct = () => {
|
|
544
|
+
if (i >= acts.length || !cursor) { if (cursor) cursor.style.opacity = '0'; return; }
|
|
545
|
+
const a = acts[i];
|
|
546
|
+
cursor.style.opacity = '1';
|
|
547
|
+
cursor.style.left = a.x + '%';
|
|
548
|
+
cursor.style.top = a.y + '%';
|
|
549
|
+
cursor.setAttribute('data-label', a.label);
|
|
550
|
+
cursor.className = `brz-cursor act-${a.type}`;
|
|
551
|
+
// 涟漪
|
|
552
|
+
const ripple = document.createElement('div');
|
|
553
|
+
ripple.className = 'brz-ripple';
|
|
554
|
+
ripple.style.left = a.x + '%';
|
|
555
|
+
ripple.style.top = a.y + '%';
|
|
556
|
+
vp.querySelector('.brz-page')?.appendChild(ripple);
|
|
557
|
+
setTimeout(() => ripple.remove(), 600);
|
|
558
|
+
i++;
|
|
559
|
+
setTimeout(runAct, 750);
|
|
560
|
+
};
|
|
561
|
+
setTimeout(runAct, 1000);
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
/* ─────────────────────────────────────────────
|
|
565
|
+
WIDGET 10: 语音输入 (voice) — 麦克风波形 + 语音识别
|
|
566
|
+
Web Audio API 真实波形 + 浏览器原生 SpeechRecognition
|
|
567
|
+
识别结果可直接作为指令传输给激活 Agent
|
|
568
|
+
───────────────────────────────────────────── */
|
|
569
|
+
WidgetRuntime.register({
|
|
570
|
+
id: 'voice',
|
|
571
|
+
title: '语音输入 · VOICE',
|
|
572
|
+
icon: '◉',
|
|
573
|
+
defaultColumn: 'right',
|
|
574
|
+
size: { maxH: 200, flex: false },
|
|
575
|
+
render(el, ctx) {
|
|
576
|
+
el.innerHTML = `
|
|
577
|
+
<div class="voice">
|
|
578
|
+
<canvas class="voice-wave" data-role="voice-wave"></canvas>
|
|
579
|
+
<div class="voice-transcript" data-role="voice-transcript">点击麦克风开始语音指令</div>
|
|
580
|
+
<div class="voice-controls">
|
|
581
|
+
<button class="voice-mic" data-role="voice-mic" title="开始/停止录音">◉</button>
|
|
582
|
+
<div class="voice-meta">
|
|
583
|
+
<div class="voice-state" data-role="voice-state">待命</div>
|
|
584
|
+
<div class="voice-hint">支持中文 · 识别后可一键传输</div>
|
|
585
|
+
</div>
|
|
586
|
+
<button class="voice-send" data-role="voice-send" disabled title="传输识别结果">传输 ❯</button>
|
|
587
|
+
</div>
|
|
588
|
+
</div>`;
|
|
589
|
+
_voiceInit(el, ctx);
|
|
590
|
+
},
|
|
591
|
+
});
|
|
592
|
+
|
|
593
|
+
function _voiceInit(el, ctx) {
|
|
594
|
+
const canvas = el.querySelector('[data-role="voice-wave"]');
|
|
595
|
+
const transcriptEl = el.querySelector('[data-role="voice-transcript"]');
|
|
596
|
+
const micBtn = el.querySelector('[data-role="voice-mic"]');
|
|
597
|
+
const sendBtn = el.querySelector('[data-role="voice-send"]');
|
|
598
|
+
const stateEl = el.querySelector('[data-role="voice-state"]');
|
|
599
|
+
|
|
600
|
+
let audioCtx = null, analyser = null, dataArr = null, rafId = null, stream = null;
|
|
601
|
+
let recognition = null, recognizing = false, finalText = '';
|
|
602
|
+
|
|
603
|
+
// 语音识别(浏览器原生)
|
|
604
|
+
const SR = window.SpeechRecognition || window.webkitSpeechRecognition;
|
|
605
|
+
if (SR) {
|
|
606
|
+
recognition = new SR();
|
|
607
|
+
recognition.lang = 'zh-CN';
|
|
608
|
+
recognition.continuous = true;
|
|
609
|
+
recognition.interimResults = true;
|
|
610
|
+
recognition.onresult = (e) => {
|
|
611
|
+
let interim = '', final = '';
|
|
612
|
+
for (let i = e.resultIndex; i < e.results.length; i++) {
|
|
613
|
+
const t = e.results[i][0].transcript;
|
|
614
|
+
if (e.results[i].isFinal) final += t; else interim += t;
|
|
615
|
+
}
|
|
616
|
+
if (final) finalText += final;
|
|
617
|
+
transcriptEl.textContent = (finalText + interim) || '聆听中...';
|
|
618
|
+
transcriptEl.classList.add('has-text');
|
|
619
|
+
sendBtn.disabled = !(finalText || interim).trim();
|
|
620
|
+
};
|
|
621
|
+
recognition.onerror = (e) => { stateEl.textContent = '识别错误: ' + e.error; };
|
|
622
|
+
} else {
|
|
623
|
+
transcriptEl.textContent = '此浏览器不支持语音识别(需 Chrome/Edge)';
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
function drawWave() {
|
|
627
|
+
if (!analyser) return;
|
|
628
|
+
rafId = requestAnimationFrame(drawWave);
|
|
629
|
+
analyser.getByteTimeDomainData(dataArr);
|
|
630
|
+
const w = canvas.width, h = canvas.height;
|
|
631
|
+
const cx = canvas.getContext('2d');
|
|
632
|
+
cx.clearRect(0, 0, w, h);
|
|
633
|
+
cx.lineWidth = 2;
|
|
634
|
+
cx.strokeStyle = '#1de9ff';
|
|
635
|
+
cx.shadowBlur = 8; cx.shadowColor = 'rgba(29,233,255,0.6)';
|
|
636
|
+
cx.beginPath();
|
|
637
|
+
const slice = w / dataArr.length;
|
|
638
|
+
let x = 0;
|
|
639
|
+
for (let i = 0; i < dataArr.length; i++) {
|
|
640
|
+
const v = dataArr[i] / 128.0;
|
|
641
|
+
const y = (v * h) / 2;
|
|
642
|
+
if (i === 0) cx.moveTo(x, y); else cx.lineTo(x, y);
|
|
643
|
+
x += slice;
|
|
644
|
+
}
|
|
645
|
+
cx.lineTo(w, h / 2);
|
|
646
|
+
cx.stroke();
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
async function startMic() {
|
|
650
|
+
try {
|
|
651
|
+
stream = await navigator.mediaDevices.getUserMedia({ audio: true });
|
|
652
|
+
audioCtx = new (window.AudioContext || window.webkitAudioContext)();
|
|
653
|
+
analyser = audioCtx.createAnalyser();
|
|
654
|
+
analyser.fftSize = 256;
|
|
655
|
+
dataArr = new Uint8Array(analyser.frequencyBinCount);
|
|
656
|
+
audioCtx.createMediaStreamSource(stream).connect(analyser);
|
|
657
|
+
canvas.width = canvas.offsetWidth; canvas.height = canvas.offsetHeight;
|
|
658
|
+
drawWave();
|
|
659
|
+
if (recognition) { finalText = ''; recognition.start(); }
|
|
660
|
+
recognizing = true;
|
|
661
|
+
micBtn.classList.add('recording');
|
|
662
|
+
stateEl.textContent = '● 录音中';
|
|
663
|
+
stateEl.style.color = '#ff4060';
|
|
664
|
+
} catch (err) {
|
|
665
|
+
stateEl.textContent = '麦克风权限被拒';
|
|
666
|
+
transcriptEl.textContent = '无法访问麦克风 · 请检查浏览器权限';
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
function stopMic() {
|
|
671
|
+
recognizing = false;
|
|
672
|
+
micBtn.classList.remove('recording');
|
|
673
|
+
stateEl.textContent = '待命';
|
|
674
|
+
stateEl.style.color = '';
|
|
675
|
+
if (rafId) cancelAnimationFrame(rafId);
|
|
676
|
+
if (recognition) try { recognition.stop(); } catch {}
|
|
677
|
+
if (stream) stream.getTracks().forEach(t => t.stop());
|
|
678
|
+
if (audioCtx) try { audioCtx.close(); } catch {}
|
|
679
|
+
const cx = canvas.getContext('2d');
|
|
680
|
+
if (cx) cx.clearRect(0, 0, canvas.width, canvas.height);
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
micBtn.onclick = () => recognizing ? stopMic() : startMic();
|
|
684
|
+
sendBtn.onclick = () => {
|
|
685
|
+
const text = transcriptEl.textContent.trim();
|
|
686
|
+
if (!text || text === '聆听中...') return;
|
|
687
|
+
stopMic();
|
|
688
|
+
// 把识别结果填入控制台并传输
|
|
689
|
+
const input = document.getElementById('consoleInput');
|
|
690
|
+
if (input) { input.value = text; }
|
|
691
|
+
if (typeof transmit === 'function') transmit();
|
|
692
|
+
transcriptEl.textContent = '已传输 → 控制台';
|
|
693
|
+
transcriptEl.classList.remove('has-text');
|
|
694
|
+
sendBtn.disabled = true;
|
|
695
|
+
};
|
|
696
|
+
}
|