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,537 @@
|
|
|
1
|
+
// chat_model_picker.js — chat 输入框旁的「下拉式模型选择器」
|
|
2
|
+
//
|
|
3
|
+
// 视觉:参考图1 (CodeBuddy 模型列表) + 图2 (「添加自定义」对话框)。
|
|
4
|
+
// 数据:全部走 foxclaw/api/routes/llm_admin.py 的 REST 端点(GET/POST/DELETE)。
|
|
5
|
+
// 状态:切换写入 FOXCLAW_DATA_DIR/.current_model,model_router 用 mtime 缓存 lazy reload,
|
|
6
|
+
// 用户改完**无需重启 foxclaw**,下次 chat 自动走新模型。
|
|
7
|
+
//
|
|
8
|
+
// 不会外泄:GET /api/llm/models 只返 has_key 布尔;POST /api/llm/custom/add 只在服务端保存。
|
|
9
|
+
|
|
10
|
+
const API_BASE = (typeof window !== 'undefined' && window.API_BASE) || '';
|
|
11
|
+
const _api = (p) => `${API_BASE}/api/llm${p}`;
|
|
12
|
+
|
|
13
|
+
let _models = { providers: [], custom: [], current: null };
|
|
14
|
+
let _menuOpen = false;
|
|
15
|
+
|
|
16
|
+
// ── 工具 ─────────────────────────────────────────────
|
|
17
|
+
|
|
18
|
+
function _esc(s) {
|
|
19
|
+
return String(s == null ? '' : s)
|
|
20
|
+
.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>')
|
|
21
|
+
.replace(/"/g, '"').replace(/'/g, ''');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// BASE URL 规范化(与后端 core/model_router.normalize_base_url 同规则):
|
|
25
|
+
// 无 scheme → 补 https://;path 为空 → 补 /v1;已有 path(/v1、/compatible-mode/v1…)原样保留。
|
|
26
|
+
// 病根:用户照厂商文档填 https://api.deepseek.com,SDK 拼出 /chat/completions → 多数网关 404/401,
|
|
27
|
+
// 用户以为是"模型填不上"。前端先收拾干净,后端再兜一层(旧记录 / 直接调 API 的场景)。
|
|
28
|
+
function _normalizeBaseUrl(u) {
|
|
29
|
+
let s = String(u || '').trim();
|
|
30
|
+
if (!s) return s;
|
|
31
|
+
if (!/^[a-zA-Z][a-zA-Z0-9+.-]*:\/\//.test(s)) s = 'https://' + s;
|
|
32
|
+
let parsed;
|
|
33
|
+
try { parsed = new URL(s); } catch { return s; }
|
|
34
|
+
if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') return s;
|
|
35
|
+
let path = parsed.pathname.replace(/\/+$/, '');
|
|
36
|
+
if (!path) path = '/v1';
|
|
37
|
+
return `${parsed.protocol}//${parsed.host}${path}${parsed.search || ''}`;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// 常见厂商的模型 ID 提示(只做 placeholder 引导,不阻断保存 —— 自建网关可能有自定义名)
|
|
41
|
+
const _MODEL_HINTS = [
|
|
42
|
+
{ re: /api\.deepseek\.com/i, hint: 'deepseek-chat', note: 'DeepSeek 官方 ID:deepseek-chat / deepseek-reasoner' },
|
|
43
|
+
{ re: /api\.openai\.com/i, hint: 'gpt-4o-mini', note: 'OpenAI 官方 ID:gpt-4o-mini / gpt-4o' },
|
|
44
|
+
{ re: /dashscope\.aliyuncs/i, hint: 'qwen-plus', note: '通义千问 ID:qwen-plus / qwen-max' },
|
|
45
|
+
{ re: /minimax/i, hint: 'MiniMax-Text-01', note: 'MiniMax ID:MiniMax-Text-01 / abab6.5s-chat' },
|
|
46
|
+
];
|
|
47
|
+
|
|
48
|
+
function _hintForBaseUrl(u) {
|
|
49
|
+
const s = String(u || '');
|
|
50
|
+
for (const h of _MODEL_HINTS) if (h.re.test(s)) return h;
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function _isCustomCurrent() {
|
|
55
|
+
return _models.current && _models.current.source === 'custom';
|
|
56
|
+
}
|
|
57
|
+
function _isPresetCurrent() {
|
|
58
|
+
return _models.current && _models.current.source === 'preset';
|
|
59
|
+
}
|
|
60
|
+
function _autoCurrent() {
|
|
61
|
+
return !_models.current;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// 当前显示在 pill 上的名称 + 颜色
|
|
65
|
+
function _currentLabel() {
|
|
66
|
+
if (_isCustomCurrent()) {
|
|
67
|
+
const m = _models.custom.find(m => m.name === _models.current.name);
|
|
68
|
+
return { name: m ? m.name : _models.current.name,
|
|
69
|
+
color: '#a78bfa', isCustom: true };
|
|
70
|
+
}
|
|
71
|
+
if (_isPresetCurrent()) {
|
|
72
|
+
const p = _models.providers.find(p => p.provider === _models.current.provider);
|
|
73
|
+
return { name: p ? p.label : _models.current.provider,
|
|
74
|
+
color: p ? p.color : '#7e93b8', isCustom: false };
|
|
75
|
+
}
|
|
76
|
+
return { name: 'Auto', color: '#7e93b8', isCustom: false };
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// ── 渲染:菜单内容 ─────────────────────────────────────
|
|
80
|
+
|
|
81
|
+
function renderMenu() {
|
|
82
|
+
const menu = document.getElementById('chatModelMenu');
|
|
83
|
+
if (!menu) return;
|
|
84
|
+
const cur = _currentLabel();
|
|
85
|
+
let h = '';
|
|
86
|
+
|
|
87
|
+
// Auto(让用户能清掉选择,退回 .env 默认)
|
|
88
|
+
h += `<div class="mp-item ${_autoCurrent() ? 'active' : ''}" data-act="auto">
|
|
89
|
+
<span class="mp-dot" style="background:#7e93b8"></span>
|
|
90
|
+
<span class="mp-name"><b>Auto</b><span>跟随 .env 默认</span></span>
|
|
91
|
+
${_autoCurrent() ? '<span class="mp-tag">当前</span>' : ''}
|
|
92
|
+
</div>`;
|
|
93
|
+
|
|
94
|
+
h += '<div class="mp-sep">预置</div>';
|
|
95
|
+
_models.providers.forEach(p => {
|
|
96
|
+
const isCur = _isPresetCurrent() && _models.current.provider === p.provider;
|
|
97
|
+
const isDis = !p.configured;
|
|
98
|
+
h += `<div class="mp-item ${isCur ? 'active' : ''} ${isDis ? 'disabled' : ''}" data-act="preset" data-prov="${_esc(p.provider)}">
|
|
99
|
+
<span class="mp-dot" style="background:${p.color};box-shadow:0 0 6px ${p.color}"></span>
|
|
100
|
+
<span class="mp-name"><b>${_esc(p.label)}</b><span>${_esc(p.provider)}</span></span>
|
|
101
|
+
${isCur ? '<span class="mp-tag mp-cur">当前</span>' :
|
|
102
|
+
isDis ? '<span class="mp-tag mp-warn">未配置</span>' : ''}
|
|
103
|
+
</div>`;
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
if (_models.custom.length) {
|
|
107
|
+
h += '<div class="mp-sep">自定义</div>';
|
|
108
|
+
_models.custom.forEach(m => {
|
|
109
|
+
const isCur = _isCustomCurrent() && _models.current.name === m.name;
|
|
110
|
+
// 三个 tag 都常驻:当前(按需显隐)+ ✎ 编辑 + ✕ 删除
|
|
111
|
+
// 即使是当前选中的,用户也应该能直接编辑它(改 key / 加 group_id),不能强制切走
|
|
112
|
+
// 删除当前选中的也安全 —— 后端 DELETE 已处理清 .current_model
|
|
113
|
+
h += `<div class="mp-item ${isCur ? 'active' : ''}" data-act="custom" data-name="${_esc(m.name)}">
|
|
114
|
+
<span class="mp-dot" style="background:#a78bfa;box-shadow:0 0 6px #a78bfa"></span>
|
|
115
|
+
<span class="mp-name"><b>${_esc(m.name)}</b><span>${_esc(m.model)}</span></span>
|
|
116
|
+
<span class="mp-tag mp-cur${isCur ? '' : ' hidden'}">当前</span>
|
|
117
|
+
<span class="mp-tag mp-edit" title="编辑(key / base_url / group_id / 模型 ID)">✎</span>
|
|
118
|
+
<span class="mp-tag mp-del" title="删除">✕</span>
|
|
119
|
+
</div>`;
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
h += `<div class="mp-foot">
|
|
124
|
+
<button class="mp-btn" data-foot="add">+ 添加自定义模型</button>
|
|
125
|
+
<button class="mp-btn" data-foot="env">📂 打开配置文件</button>
|
|
126
|
+
</div>`;
|
|
127
|
+
|
|
128
|
+
menu.innerHTML = h;
|
|
129
|
+
|
|
130
|
+
// 事件
|
|
131
|
+
menu.querySelectorAll('.mp-item').forEach(el => {
|
|
132
|
+
el.addEventListener('click', (e) => {
|
|
133
|
+
if (e.target.classList.contains('mp-del')) {
|
|
134
|
+
e.stopPropagation();
|
|
135
|
+
const name = el.dataset.name;
|
|
136
|
+
if (confirm(`删除自定义模型「${name}」?`)) deleteCustom(name);
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
if (e.target.classList.contains('mp-edit')) {
|
|
140
|
+
e.stopPropagation();
|
|
141
|
+
editCustom(el.dataset.name);
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
const act = el.dataset.act;
|
|
145
|
+
if (act === 'auto') selectModel('auto', null, null);
|
|
146
|
+
else if (act === 'preset') selectModel('preset', el.dataset.prov, null);
|
|
147
|
+
else if (act === 'custom') selectModel('custom', null, el.dataset.name);
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
menu.querySelectorAll('.mp-foot .mp-btn').forEach(btn => {
|
|
151
|
+
btn.addEventListener('click', (e) => {
|
|
152
|
+
e.stopPropagation();
|
|
153
|
+
if (btn.dataset.foot === 'add') openAddDialog();
|
|
154
|
+
else if (btn.dataset.foot === 'env') window.open('/.env', '_blank');
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function renderPill() {
|
|
160
|
+
const cur = _currentLabel();
|
|
161
|
+
const dot = document.getElementById('chatModelDot');
|
|
162
|
+
const name = document.getElementById('chatModelName');
|
|
163
|
+
if (dot) dot.style.cssText = `background:${cur.color};box-shadow:0 0 6px ${cur.color}`;
|
|
164
|
+
if (name) name.textContent = cur.name;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// ── API ─────────────────────────────────────────────
|
|
168
|
+
|
|
169
|
+
async function loadModels() {
|
|
170
|
+
try {
|
|
171
|
+
const r = await fetch(_api('/models'));
|
|
172
|
+
if (!r.ok) throw new Error(`HTTP ${r.status}`);
|
|
173
|
+
_models = await r.json();
|
|
174
|
+
} catch (e) {
|
|
175
|
+
console.warn('[chat_model_picker] load /models failed', e);
|
|
176
|
+
_models = { providers: [], custom: [], current: null };
|
|
177
|
+
}
|
|
178
|
+
renderPill();
|
|
179
|
+
renderMenu();
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
async function selectModel(source, provider, name) {
|
|
183
|
+
try {
|
|
184
|
+
const body = { source };
|
|
185
|
+
if (source === 'preset' && provider) body.provider = provider;
|
|
186
|
+
if (source === 'custom' && name) body.name = name;
|
|
187
|
+
const r = await fetch(_api('/select'), {
|
|
188
|
+
method: 'POST',
|
|
189
|
+
headers: { 'Content-Type': 'application/json' },
|
|
190
|
+
body: JSON.stringify(body),
|
|
191
|
+
});
|
|
192
|
+
if (!r.ok) {
|
|
193
|
+
let msg = `HTTP ${r.status}`;
|
|
194
|
+
try { const j = await r.json(); msg = j.detail || JSON.stringify(j); } catch {}
|
|
195
|
+
alert(`切换失败: ${msg}`);
|
|
196
|
+
return false;
|
|
197
|
+
}
|
|
198
|
+
const j = await r.json();
|
|
199
|
+
_models.current = j.current;
|
|
200
|
+
_menuOpen = false;
|
|
201
|
+
document.getElementById('chatModelMenu')?.classList.remove('show');
|
|
202
|
+
renderPill();
|
|
203
|
+
renderMenu();
|
|
204
|
+
return true;
|
|
205
|
+
} catch (e) {
|
|
206
|
+
alert(`切换失败: ${e.message || e}`);
|
|
207
|
+
return false;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
async function deleteCustom(name) {
|
|
212
|
+
try {
|
|
213
|
+
const r = await fetch(_api(`/custom/${encodeURIComponent(name)}`), { method: 'DELETE' });
|
|
214
|
+
if (!r.ok) { alert('删除失败'); return; }
|
|
215
|
+
await loadModels();
|
|
216
|
+
} catch (e) { alert(`删除失败: ${e.message || e}`); }
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
async function addCustom(payload) {
|
|
220
|
+
const r = await fetch(_api('/custom/add'), {
|
|
221
|
+
method: 'POST',
|
|
222
|
+
headers: { 'Content-Type': 'application/json' },
|
|
223
|
+
body: JSON.stringify(payload),
|
|
224
|
+
});
|
|
225
|
+
if (!r.ok) {
|
|
226
|
+
let msg = `HTTP ${r.status}`;
|
|
227
|
+
try { const j = await r.json(); msg = j.detail || JSON.stringify(j); } catch {}
|
|
228
|
+
throw new Error(msg);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
async function getCustom(name) {
|
|
233
|
+
// 取单个自定义模型详情(后端不返回 api_key 明文,只返 has_key)
|
|
234
|
+
const r = await fetch(_api(`/custom/${encodeURIComponent(name)}`));
|
|
235
|
+
if (!r.ok) throw new Error(`HTTP ${r.status}`);
|
|
236
|
+
return r.json();
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
async function updateCustom(name, payload) {
|
|
240
|
+
// payload 字段语义:填了非空 = 用新值;没传(或不传该字段)= 不变;api_key 留空=保留原值
|
|
241
|
+
const r = await fetch(_api(`/custom/${encodeURIComponent(name)}`), {
|
|
242
|
+
method: 'PUT',
|
|
243
|
+
headers: { 'Content-Type': 'application/json' },
|
|
244
|
+
body: JSON.stringify(payload),
|
|
245
|
+
});
|
|
246
|
+
if (!r.ok) {
|
|
247
|
+
let msg = `HTTP ${r.status}`;
|
|
248
|
+
try { const j = await r.json(); msg = j.detail || JSON.stringify(j); } catch {}
|
|
249
|
+
throw new Error(msg);
|
|
250
|
+
}
|
|
251
|
+
return r.json();
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
async function editCustom(name) {
|
|
255
|
+
// 加载详情 → 复用 openAddDialog 切到 edit 模式预填表单
|
|
256
|
+
try {
|
|
257
|
+
const m = await getCustom(name);
|
|
258
|
+
openAddDialog('edit', { ...m, _editingName: name });
|
|
259
|
+
} catch (e) {
|
|
260
|
+
alert(`加载详情失败: ${e.message || e}`);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
async function testModel(source, provider, name) {
|
|
265
|
+
const body = { source };
|
|
266
|
+
if (source === 'preset' && provider) body.provider = provider;
|
|
267
|
+
if (source === 'custom' && name) body.name = name;
|
|
268
|
+
const r = await fetch(_api('/test'), {
|
|
269
|
+
method: 'POST',
|
|
270
|
+
headers: { 'Content-Type': 'application/json' },
|
|
271
|
+
body: JSON.stringify(body),
|
|
272
|
+
});
|
|
273
|
+
if (!r.ok) throw new Error(`HTTP ${r.status}`);
|
|
274
|
+
return r.json();
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// ── 添加对话框(图2 风格)────────────────────────────
|
|
278
|
+
|
|
279
|
+
// 对话框全局状态:add / edit 模式共用同一表单
|
|
280
|
+
let _cmMode = 'add'; // 'add' | 'edit'
|
|
281
|
+
let _cmEditingName = null; // edit 模式下的原名(PUT URL 用);改名后仍指向磁盘上那条记录
|
|
282
|
+
|
|
283
|
+
function openAddDialog(mode = 'add', preset = null) {
|
|
284
|
+
_cmMode = mode;
|
|
285
|
+
_cmEditingName = (mode === 'edit' && preset)
|
|
286
|
+
? (preset._editingName || preset.name)
|
|
287
|
+
: null;
|
|
288
|
+
|
|
289
|
+
const mask = document.getElementById('cmAddMask');
|
|
290
|
+
if (!mask) return;
|
|
291
|
+
|
|
292
|
+
// 标题 + 副标题
|
|
293
|
+
const title = document.getElementById('cmAddTitle');
|
|
294
|
+
if (title) {
|
|
295
|
+
title.textContent = mode === 'edit' && preset?.name
|
|
296
|
+
? `编辑自定义模型 · ${preset.name}`
|
|
297
|
+
: '添加自定义模型';
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
// 填表单 — api_key 永远不清空回填(安全考虑)
|
|
301
|
+
const set = (id, v) => { const el = document.getElementById(id); if (el) el.value = v || ''; };
|
|
302
|
+
set('cm_name', preset?.name);
|
|
303
|
+
set('cm_base_url', preset?.base_url);
|
|
304
|
+
set('cm_api_key', '');
|
|
305
|
+
set('cm_model', preset?.model);
|
|
306
|
+
set('cm_group_id', preset?.group_id);
|
|
307
|
+
set('cm_extra_headers', preset?.extra_headers && Object.keys(preset.extra_headers).length
|
|
308
|
+
? JSON.stringify(preset.extra_headers) : '');
|
|
309
|
+
set('cm_note', preset?.note);
|
|
310
|
+
_applyModelHint(preset?.base_url);
|
|
311
|
+
|
|
312
|
+
// API KEY 字段 placeholder 区分 add / edit
|
|
313
|
+
const keyInp = document.getElementById('cm_api_key');
|
|
314
|
+
if (keyInp) {
|
|
315
|
+
keyInp.placeholder = (mode === 'edit' && preset?.has_key)
|
|
316
|
+
? '留空保持原值;填入则覆盖'
|
|
317
|
+
: '请输入 API Key';
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
const msg = document.getElementById('cm_msg');
|
|
321
|
+
if (msg) { msg.textContent = ''; msg.className = 'cm-msg'; }
|
|
322
|
+
mask.classList.add('show');
|
|
323
|
+
setTimeout(() => document.getElementById('cm_name')?.focus(), 50);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
// 已知厂商的"模型 ID 写错"软提示(只警告不阻断 —— 自建网关可以有自定义别名)
|
|
327
|
+
function _modelWarning(baseUrl, modelId) {
|
|
328
|
+
const s = String(baseUrl || ''), m = String(modelId || '').trim();
|
|
329
|
+
if (!m) return '';
|
|
330
|
+
if (/api\.deepseek\.com/i.test(s) && !/^deepseek-(chat|reasoner)$/.test(m))
|
|
331
|
+
return `⚠ DeepSeek 官方没有「${m}」,应填 deepseek-chat 或 deepseek-reasoner`;
|
|
332
|
+
return '';
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
// 按 BASE URL 域名更新「模型 ID」的 placeholder + 副标题提示(不阻断保存)
|
|
336
|
+
function _applyModelHint(baseUrl) {
|
|
337
|
+
const hint = _hintForBaseUrl(baseUrl);
|
|
338
|
+
const inp = document.getElementById('cm_model');
|
|
339
|
+
if (inp) inp.placeholder = hint ? `例:${hint.hint}` : '例:MiniMax-Text-01';
|
|
340
|
+
const sub = document.getElementById('cmAddSubHint');
|
|
341
|
+
if (sub) {
|
|
342
|
+
const warn = _modelWarning(baseUrl, inp?.value);
|
|
343
|
+
sub.textContent = warn || (hint ? hint.note : '');
|
|
344
|
+
sub.style.color = warn ? '#e0685a' : '#e0a45c';
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
function closeAddDialog() {
|
|
349
|
+
document.getElementById('cmAddMask')?.classList.remove('show');
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
function _setMsg(text, kind) {
|
|
353
|
+
const msg = document.getElementById('cm_msg');
|
|
354
|
+
if (!msg) return;
|
|
355
|
+
msg.textContent = text;
|
|
356
|
+
msg.className = 'cm-msg' + (kind ? ' cm-msg-' + kind : '');
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
function _readForm() {
|
|
360
|
+
const v = (id) => (document.getElementById(id)?.value || '').trim();
|
|
361
|
+
const out = {
|
|
362
|
+
name: v('cm_name'),
|
|
363
|
+
// 保存前再规范化一次(用户可能没触发 blur 直接点保存);后端也会兜一层
|
|
364
|
+
base_url: _normalizeBaseUrl(v('cm_base_url')),
|
|
365
|
+
api_key: v('cm_api_key'),
|
|
366
|
+
model: v('cm_model'),
|
|
367
|
+
group_id: v('cm_group_id'),
|
|
368
|
+
note: v('cm_note'),
|
|
369
|
+
};
|
|
370
|
+
const raw = v('cm_extra_headers');
|
|
371
|
+
if (raw) {
|
|
372
|
+
try {
|
|
373
|
+
const parsed = JSON.parse(raw);
|
|
374
|
+
if (typeof parsed === 'object' && parsed && !Array.isArray(parsed)) {
|
|
375
|
+
out.extra_headers = parsed;
|
|
376
|
+
} else { throw new Error('必须是 JSON object'); }
|
|
377
|
+
} catch (e) {
|
|
378
|
+
throw new Error(`额外 header JSON 不合法: ${e.message}`);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
return out;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
async function _onSave() {
|
|
385
|
+
try {
|
|
386
|
+
const payload = _readForm();
|
|
387
|
+
// name / base_url / model 必填;api_key 在 edit 模式下留空 = 保留(后端校验)
|
|
388
|
+
if (!payload.name || !payload.base_url || !payload.model) {
|
|
389
|
+
_setMsg('请填全 * 号必填项', 'err');
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
if (_cmMode === 'add' && !payload.api_key) {
|
|
393
|
+
_setMsg('add 模式必须填 API KEY(edit 模式可留空保留原值)', 'err');
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
396
|
+
_setMsg('保存中…', 'info');
|
|
397
|
+
let savedName = payload.name;
|
|
398
|
+
if (_cmMode === 'add') {
|
|
399
|
+
await addCustom(payload);
|
|
400
|
+
savedName = payload.name;
|
|
401
|
+
} else {
|
|
402
|
+
const r = await updateCustom(_cmEditingName, payload);
|
|
403
|
+
savedName = r.name;
|
|
404
|
+
// 改名后,_cmEditingName 失效 → 下次 _onTest 会失败 → 清掉,避免误测
|
|
405
|
+
_cmEditingName = r.name;
|
|
406
|
+
}
|
|
407
|
+
await loadModels();
|
|
408
|
+
// 保存即生效 —— 用户点「保存」的诉求就是「用它」。
|
|
409
|
+
// 病根:此前只写盘不切换,聊天仍走 .env 的旧 provider,用户看到 AuthenticationError/stub,
|
|
410
|
+
// 以为是"模型填不上";实际上是要再回菜单点一次这个条目。现在省掉这一步。
|
|
411
|
+
_setMsg('已保存,正在切换…', 'info');
|
|
412
|
+
const ok = await selectModel('custom', null, savedName);
|
|
413
|
+
_setMsg(ok ? `已保存并切换到 ${savedName}` : `已保存 ${savedName},但切换失败(见弹窗)`,
|
|
414
|
+
ok ? 'ok' : 'err');
|
|
415
|
+
setTimeout(closeAddDialog, 600);
|
|
416
|
+
} catch (e) {
|
|
417
|
+
_setMsg(`保存失败: ${e.message || e}`, 'err');
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
async function _onTest() {
|
|
422
|
+
try {
|
|
423
|
+
const payload = _readForm();
|
|
424
|
+
if (!payload.base_url || !payload.model) {
|
|
425
|
+
_setMsg('请先填 BASE URL / 模型 ID 再测', 'err');
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
428
|
+
if (_cmMode === 'edit') {
|
|
429
|
+
// edit 模式:测磁盘上**已保存**的配置(避免被 form 里未保存的改动误导)
|
|
430
|
+
// 若想测表单里的新值,先点「保存」再点「测试连通性」
|
|
431
|
+
_setMsg(`测试已保存配置(${_cmEditingName})…`, 'info');
|
|
432
|
+
const r = await testModel('custom', null, _cmEditingName);
|
|
433
|
+
if (r.ok) {
|
|
434
|
+
_setMsg(`✓ 连通 (${r.latency_ms} ms, model=${r.model}, reply="${(r.reply || '').slice(0, 30)}")`, 'ok');
|
|
435
|
+
} else {
|
|
436
|
+
_setMsg(`✗ 连通失败: ${(r.error || '').slice(0, 200)}\n(测的是已保存配置;要测表单里的新值请先点「保存」)`, 'err');
|
|
437
|
+
}
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
440
|
+
// add 模式:必须 name + api_key,临时 add 一个 tmp 名测,失败保留
|
|
441
|
+
if (!payload.name || !payload.api_key) {
|
|
442
|
+
_setMsg('add 模式请先填「模型名称」+「API KEY」再测试', 'err');
|
|
443
|
+
return;
|
|
444
|
+
}
|
|
445
|
+
_setMsg('保存并测试中…', 'info');
|
|
446
|
+
await addCustom(payload);
|
|
447
|
+
const r = await testModel('custom', null, payload.name);
|
|
448
|
+
if (r.ok) {
|
|
449
|
+
// 测试通过 = 这份配置真的能用 → 直接切过去,不用用户再回菜单点一次
|
|
450
|
+
await loadModels();
|
|
451
|
+
await selectModel('custom', null, payload.name);
|
|
452
|
+
_setMsg(`✓ 连通 (${r.latency_ms} ms, model=${r.model}) — 已切换`, 'ok');
|
|
453
|
+
} else {
|
|
454
|
+
_setMsg(`✗ 连通失败: ${(r.error || '').slice(0, 200)}\n(已为你保留,可手动改后再测或删除)`, 'err');
|
|
455
|
+
}
|
|
456
|
+
await loadModels();
|
|
457
|
+
} catch (e) {
|
|
458
|
+
_setMsg(`测试失败: ${e.message || e}`, 'err');
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
// ── 事件绑定 ─────────────────────────────────────
|
|
463
|
+
|
|
464
|
+
function bindEvents() {
|
|
465
|
+
const pill = document.getElementById('chatModelPill');
|
|
466
|
+
const menu = document.getElementById('chatModelMenu');
|
|
467
|
+
if (pill && menu) {
|
|
468
|
+
pill.addEventListener('click', (e) => {
|
|
469
|
+
e.stopPropagation();
|
|
470
|
+
_menuOpen = !_menuOpen;
|
|
471
|
+
menu.classList.toggle('show', _menuOpen);
|
|
472
|
+
});
|
|
473
|
+
// 点外面收起
|
|
474
|
+
document.addEventListener('click', (e) => {
|
|
475
|
+
if (!_menuOpen) return;
|
|
476
|
+
if (e.target.closest('#chatModelPick')) return;
|
|
477
|
+
_menuOpen = false;
|
|
478
|
+
menu.classList.remove('show');
|
|
479
|
+
});
|
|
480
|
+
}
|
|
481
|
+
const closeBtn = document.getElementById('cmAddClose');
|
|
482
|
+
const cancelBtn = document.getElementById('cm_cancel');
|
|
483
|
+
const saveBtn = document.getElementById('cm_save');
|
|
484
|
+
const testBtn = document.getElementById('cm_test');
|
|
485
|
+
const eyeBtn = document.getElementById('cm_eye');
|
|
486
|
+
const mask = document.getElementById('cmAddMask');
|
|
487
|
+
if (closeBtn) closeBtn.addEventListener('click', closeAddDialog);
|
|
488
|
+
if (cancelBtn) cancelBtn.addEventListener('click', closeAddDialog);
|
|
489
|
+
if (saveBtn) saveBtn.addEventListener('click', _onSave);
|
|
490
|
+
if (testBtn) testBtn.addEventListener('click', _onTest);
|
|
491
|
+
if (eyeBtn) {
|
|
492
|
+
eyeBtn.addEventListener('click', () => {
|
|
493
|
+
const inp = document.getElementById('cm_api_key');
|
|
494
|
+
if (!inp) return;
|
|
495
|
+
inp.type = inp.type === 'password' ? 'text' : 'password';
|
|
496
|
+
});
|
|
497
|
+
}
|
|
498
|
+
if (mask) {
|
|
499
|
+
mask.addEventListener('click', (e) => {
|
|
500
|
+
if (e.target === mask) closeAddDialog();
|
|
501
|
+
});
|
|
502
|
+
}
|
|
503
|
+
// BASE URL 失焦即规范化(补 https:// / 补 /v1),并联动模型 ID 提示
|
|
504
|
+
const baseInp = document.getElementById('cm_base_url');
|
|
505
|
+
if (baseInp) {
|
|
506
|
+
baseInp.addEventListener('blur', () => {
|
|
507
|
+
const v = baseInp.value.trim();
|
|
508
|
+
if (!v) return;
|
|
509
|
+
baseInp.value = _normalizeBaseUrl(v);
|
|
510
|
+
_applyModelHint(baseInp.value);
|
|
511
|
+
});
|
|
512
|
+
baseInp.addEventListener('input', () => _applyModelHint(baseInp.value));
|
|
513
|
+
}
|
|
514
|
+
const modelInp = document.getElementById('cm_model');
|
|
515
|
+
if (modelInp) modelInp.addEventListener('input', () => _applyModelHint(baseInp?.value));
|
|
516
|
+
document.addEventListener('keydown', (e) => {
|
|
517
|
+
if (e.key === 'Escape') {
|
|
518
|
+
if (mask?.classList.contains('show')) closeAddDialog();
|
|
519
|
+
if (_menuOpen) { _menuOpen = false; menu?.classList.remove('show'); }
|
|
520
|
+
}
|
|
521
|
+
});
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
// ── 启动 ─────────────────────────────────────────
|
|
525
|
+
|
|
526
|
+
(function init() {
|
|
527
|
+
bindEvents();
|
|
528
|
+
loadModels();
|
|
529
|
+
// 多 tab 同步:监听 storage 事件
|
|
530
|
+
window.addEventListener('storage', (e) => {
|
|
531
|
+
if (e.key === '__foxclaw_model_changed__') loadModels();
|
|
532
|
+
});
|
|
533
|
+
// 切完模型后,广播给其它 tab(简版:周期性 reload)
|
|
534
|
+
setInterval(() => {
|
|
535
|
+
if (_menuOpen) loadModels();
|
|
536
|
+
}, 5000);
|
|
537
|
+
})();
|